
    h                    <   S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
r
S SKrS SKrS SKrS SKJr  S SKJr  S SKJr  S SKJrJrJrJrJrJrJrJrJrJrJrJ r   S SK!J"r"  S S	K#J$r$  S S
K%J&r&  S SK'J(r(J)r)  S SK*J+r+J,r-  S SK.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7  \(       a  S SK8J9r9  S SK:J;r;  S SK!J<r<J=r=J>r>J?r?J@r@  / SQrA\R                  " S5      rCSrDSrE " S S\$R                  5      rG0 SS_SS_SS_SS_SS _S!S"_S#S$_S%S&_S'S(_S)S*_S+S,_S-S._S/S0_S1S2_S3S4_S5S6_S7S8_S9S:S;S<S=S>S?S@SASBSCSDSE.ErH " SF SG5      rI Sl   SmSH jjrJSnSI jrKSoSJ jrLSpSK jrM\R                  \R                  \R                  1rQSqSL jrRSrSM jrSSsSN jrTStSO jrU        SrSP jrVSuSQ jrWSuSR jrX\4SvSS jjrYSwST jrZ " SU SV5      r[ " SW SX\R                  5      r] " SY SZ\R                  5      r_\_R                  \\_R                  \* \_R                  \* \_R                  \0rd " S[ S\\R                  5      re " S] S^\R                  5      rf " S_ S`\R                  5      rg " Sa Sb\R                  5      rh\ " Sc Sd5      5       riSxSe jrj " Sf Sg\
R                  5      rl " Sh Si\l5      rm " Sj Sk\l5      rng)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                      \ rS rSrSrg)ConnectionTypeError[    N)__name__
__module____qualname____firstlineno____static_attributes__r?       F/var/www/html/env/lib/python3.13/site-packages/ezdxf/render/mleader.pyr=   r=   [   s    rE   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                  2    \ rS rSrSS jrSS jrS	S jrSrg)
MLeaderStyleOverride   c                   UR                   U l        UR                   U l        UR                  U l        UR                   R                  SS5      U l        [        UR                   R                  SS5      UR                   R                  SS5      UR                   R                  SS5      45      U l        [        U R                  S-  5      U l
        g )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      rF   __init__MLeaderStyleOverride.__init__   s    ))#KK(/%q)
% $(		os3		os3		os3$
  *.))W5*
&rE   c                   US:X  a  U R                   nOU R                  R                  U5      n[        (       d  U R	                  U5      (       a9  US:X  a  U R
                  R                  nU$ U R                  R                  X5      nU$ )Nrd   r`   )	r}   rw   get_defaultIGNORE_OVERRIDE_FLAGSis_overriddenrz   r`   rx   r{   )r   attrib_namevalues      rF   r{   MLeaderStyleOverride.get   s{    ..,,EOO//<E  D$6$6{$C$Cm+11  ))--kArE   c                \    [         R                  US5      n[        X R                  -  5      $ Nr   )OVERRIDE_FLAGr{   r~   r|   )r   r   flags      rF   r   "MLeaderStyleOverride.is_overridden   s(      a0D88899rE   )r}   rz   rx   r|   rw   r   N)r   r&   r   r(   )r   strreturnr   )r   r   r   r~   )r@   rA   rB   rC   r   r{   r   rD   r?   rE   rF   rn   rn      s    
$:rE   rn   c                    U R                   nUc   S5       eU(       a1  U R                  b$  [        U R                  U5      R                  5       $ [	        [        X5      R                  5       5      $ )Nvalid DXF document required)docproxy_graphicr   r1   iterRenderEnginerun)r   r   r   s      rF   r1   r1      s`     ++C?999?..:G1137HHJJL.22455rE   c                   U R                   R                  nUR                  R                  U5      nUc4  [        R                  SU S35        UR                  R                  S5      nUc   S5       e[        [        [        U5      U 5      $ )Nzreferenced MLEADERSTYLE(#() does not exist, replaced by 'Standard'Standardz0mandatory MLEADERSTYLE 'Standard' does not exist)
rv   style_handleentitydbr{   loggerwarningmleader_stylesrn   r
   r&   )r   r   handler   s       rF   	get_styler      s    [[%%FLLV$E}'x 0% &	
 ""&&z2PPP\5 97CCrE   c                    UR                   R                  U 5      nUc4  [        R                  SU  S35        UR                  R                  S5      nUc   S5       eU$ )Nzreferenced STYLE(#r   r   z)mandatory STYLE 'Standard' does not exist)r   r{   r   r   styles)r   r   
text_styles      rF   get_text_styler      se    !!&)J  )% &	
 ZZ^^J/
!N#NN!rE   c                b    [        U 5      S:  a  [        $ U S   U S   -
  nUR                  5       $ )NrJ   rH   r   )lenr   	normalize)vertices	directions     rF   get_arrow_directionr      s4    
8}qhqk)I  rE   c                    [         R                  nS n[         R                  " U 5      u  p4U[        ;   a  UnX4$ U[         R                  :X  a  UnX4$ N)r   BYBLOCKdecode_raw_color_intACI_COLOR_TYPESCOLOR_TYPE_RGB)	raw_color	aci_color
true_color
color_typecolors        rF   decode_raw_colorr      sY    I $J33I>J_$	    
v,,	,
  rE   c                   UR                   U l        U R                  n[        UR                  5      u  pEXCl        Ub  XSl        UR                  Ul        U R                  c   e[        UR                  U R                  5      R                  R                  U R                  l        UR                  R                  [        5      (       d  UR                  Ul        UR                  Ul        UR                   U-  Ul        UR"                  Ul        UR$                  Ul        UR&                  Ul        UR(                  Ul        g r   )default_contentr    rv   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_datarg   rv   r   r   s         rF   copy_mtext_datar      s    ++EJ
))C,Z-=-=>II#""CJ99   $	c$$ 
IIO ''//",,#22C  5(CI(<<C'::C#22C%//CrE   c                   [        S[        R                  " SU R                  S95      nU R                  R
                  UR                  l        U R                  nUR                  nUc  [        S5      eUR                  nUR                  UR                  l
        Ub4  [        XU5        UR                  (       a  [        X5        [        XU5        U$ )Nr.   MTEXT)r   z MULTILEADER has no MTEXT content)r
   r   newr   rv   layerry   r   	TypeErrorrg   r`   r   has_bg_fillset_mtext_bg_fillset_mtext_columns)r   r   ry   r   rg   s        rF   
make_mtextr      s    '++g7;;?@Ekk''EIIOooGJ:<<MME#//EII51!!e0%U3LrE   c                    UR                   U R                  l        SU R                  l        [        R
                  U R                  l        UR                  U R                  l        [        R                  " UR                  5      u  p#U[        ;   a  X0R                  l        O$U[        R                  :X  a  X0R                  l        UR                  (       d  U[        R                  :X  a  SU R                  l        g g )NrH      )bg_scale_factorrv   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       rF   r   r     s      *99EIIEII$nnEII%/%?%?EII"33J4G4GHJ_$"'			v,,	,',		$ 	&&444 		 5rE   c                    g r   r?   )r   r   rg   s      rF   r   r   &  s    
 	rE   c                    U R                   nUR                  b  UR                  R                  $ UR                  b  UR                  R                  $ UR                  $ r   )ry   r   r   blockplane_originentityry   s     rF   _get_insertr   .  sK    nnG}} }}###		"}}###rE   c                    U R                   nUR                  b  UR                  R                  $ UR                  b  UR                  R                  $ UR                  $ r   )ry   r   r   r   plane_z_axisr   s     rF   _get_extrusionr   7  sK    nnG}} }}&&&		"}}&&&rE   c                     U R                   (       a%  U R                  R                  U R                  5      $  UR                  U R                  5      $ ! [         a     N'f = fr   )has_dogleg_vectordogleg_vectorr   rU   ZeroDivisionError)leaderdefaults     rF   _get_dogleg_vectorr   @  s_    ##''11&2F2FGG $ V1122  s   5A 
A! A!c                    UR                   R                  U 5      nUc  [        R                  SU  S35        g UR                  R                  S5      $ )Nzrequired BLOCK_RECORD entity # does not existr   )r   r{   r   errorrv   )r   r   block_records      rF   _get_block_namer   J  sL    <<##F+L5fX_MN''rE   c                  `   \ rS rSrSS jr\SS j5       r\SS j5       r\SS j5       r\SS j5       r	SS jr
SS jrS S	 jrS!S"S jjrS#S jrS#S jrS#S jrS#S jrS$S jrS#S jrS%S jrS%S jr S&     S'S jjrS(S jrS)S jr  S*     S+S jjrS!S,S jjr          S-S jrSrg
).r   iR  c                j   / U l         Xl        X l        [        X5      U l        UR
                  U l        [        U5      U l        [        U5      U l	        S U l
        U R                  R                  [        5      (       d  [        U R                  5      U l
        U R                  R                  U l        U R
                  R                   U l        UR"                  R$                  U l        U R'                  5       U l        U R                  R+                  S5      U l        [/        U R                  R+                  S5      5      u  p4X0l        X@l        U R                  R+                  S5      U l        SU l        [9        U R                  R+                  S5      5      U l        UR<                   Vs0 s H  oUR>                  UR@                  _M     snU l        U R                  R+                  S5      U l!        S U l"        S U l#        [9        U R                  R+                  S5      5      U l$        U R                  R+                  S5      U l%        U R                  R+                  S	5      U l&        U R                  R+                  S
5      U l'        U R                  R+                  S5      U l(        g s  snf )NrM   rI   rG   FrS   rW   rj   r\   rh   rk   rl   ))entitiesr   r   r   r   ry   r   r   r   r   ocsr   r   r   z	elevationrg   rv   r   linetype_namelinetyper{   
lineweightr   leader_aci_colorleader_true_colorrG   ra   r~   rS   arrow_headsindexr   rW   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         rF   r   RenderEngine.__init__S  s   *,+4W+B
!'*-g6"&~~%%f--4>>*DH $ !LL..
[[&&
**,**..)<= 0JJNN./!
	 &/0: $

} =# $TZZ^^L%A B070C0C,
0CJJ#0C,
 "&0C!D37AE)-JJNN67*
& %)JJNN3N$O!%)ZZ^^(&
" $(::>>2L#M &*jjnn)'
#,
s   0 J0c                    U R                   S L$ r   )r   r   s    rF   has_extrusionRenderEngine.has_extrusion  s    xxt##rE   c                2    U R                   R                  S L$ r   )ry   r   r  s    rF   has_text_contentRenderEngine.has_text_content      ||!!--rE   c                2    U R                   R                  S L$ r   )ry   r   r  s    rF   has_block_contentRenderEngine.has_block_content  r  rE   c                    U R                   b  U R                   $ U R                  b#  [        R                  " U R                  5      u  pOSu  pX4U l         U R                   $ )z Calculate MTEXT width on demand.        r  )r  r  r   estimate_mtext_extents)r   r   heights      rF   mtext_extentsRenderEngine.mtext_extents  sf     "".***  , &<<%%ME6 %ME#(/&&&rE   c                    U R                   R                  5         [        U R                  5      S:  a   U R	                  5         U R                  5         U R                   $ )z'Entry point to render MLEADER entities.&.>)r   clearabsrg   add_contentadd_leadersr  s    rF   r   RenderEngine.run  sD    tzz?T!}}rE   c                    U R                   R                  S5      nU R                  R                  R                  U5      nUb  UR                  R
                  $ [        R                  SU SU R                   35        g)NrK   zinvalid linetype handle # in 
Continuous)	r   r{   r   r   rv   r   r   r   r   )r   r   ltypes      rF   r   RenderEngine.linetype_name  sd     89!!%%f-99>>!26($t||nMNrE   c                2   SnU R                   R                  XR                  5      nUb  US:X  a  U$ U R                  R                  R                  U5      nUc(  [
        R                  SU SU R                   S35        U$ UR                  R                  $ )N_CLOSED_FILLED0zarrow block #r%  z0 does not exist, replaced by closed filled arrow)
r   r{   rW   r   r   r   r   r   rv   r   )r   r  closed_filledr   r   s        rF   arrow_block_nameRenderEngine.arrow_block_name  s    (!!%%e-C-CD>Vs]  xx((,,V4NNxtDLL> :2 3 ! $$$rE   Nc                    U R                   nU R                  nU(       a   U[        R                  La  [	        U5      u  p#U R
                  UU R                  U R                  S.nUb  X4S'   U$ )N)r   r   r   r   r   )r   r   r   BY_BLOCK_RAW_VALUEr   r   r   r   )r   r   r   r   attribss        rF   leader_line_attribs RenderEngine.leader_line_attribs  sm    ))	++
 &*C*CC$4Y$?!I ZZ//	
 !$.L!rE   c                    U R                   (       a  U R                  5         g U R                  (       a  U R                  5         g g r   )r  add_mtext_contentr  add_block_contentr  s    rF   r!  RenderEngine.add_content  s1      ""$##""$ $rE   c                    [        U R                  5      nU R                  R                  U5        Xl        U R
                  (       a  U R                  5         g g r   )r   r   r   appendr  ra   add_text_frame)r   r   s     rF   r5  RenderEngine.add_mtext_content  sB    4<<(U# %! rE   c                    g r   r?   r  s    rF   r:  RenderEngine.add_text_frame  s     	rE   c           	        U R                   R                  nUc   e[        UR                  U R                  5      nUc  g UR
                  n[        R                  " UR                  5      nU R                  b  U R                  R                  U5      n[        UR                  5      u  pVUR                  nUUUUUR                  UR                  UR                   UR"                  S.nUb  XhS'   [%        S[&        R(                  " SXR                  S95      n	U R*                  R-                  U	5        U R.                  R0                  (       a  U R3                  U	5        g g )N)r   r   rotationr   r   xscaleyscalezscaler   r-   INSERT
dxfattribsr   )ry   r   r   rb   r   r   mathdegreesr?  r   from_wcsr   r   rg   r   xyr   r
   r   r   r   r9  r   block_attribsadd_block_attributes)
r   r   
block_namelocationr?  r   r   rg   r1  r   s
             rF   r6  RenderEngine.add_block_content  s"   ""   $U%>%>I
<<<</88xx((2H 0 =	  gggggg	
 !$.L!gkk(wHHM
 	V$<<%%%%f- &rE   c                ~   U R                   R                  n[        5       nU R                  R                   Hj  nUR                  UR                  5      nUc%  [        R                  SUR                   S35        MF  UR                  R                  nUR                  X6'   Ml     U(       a  UR                  U5        g g )Nzrequired ATTDEF entity #r   )r   r   dictr   rK  r{   r   r   r   rv   tagr    add_auto_attribs)r   r   r   valuesattribattdefrR  s          rF   rL  !RenderEngine.add_block_attributes  s    88$$!%ll00F\\&--0F~.v}}o_M **..C ++FK 1 ##F+ rE   c                8   U R                   S:X  a  g U R                  R                   Ho  nUR                   H  nU R	                  X5        M     U R
                  (       d  M:  UR                  (       a  U R                  U5        M^  U R                  U5        Mq     g r   )	rG   ry   leaderslinesadd_leader_liner  r  add_text_underlineadd_overline)r   r   lines      rF   r"  RenderEngine.add_leaders  sz    q ll**F$$V2 % $$$33 ++F3 %%f- +rE   c                b   U R                   R                  nUc  g U R                  S;   nU R                  S;   nU(       d  U(       d  g UR                  [        U5      -   nU R                  u  pgX`R                   R                  -   nUS:  a  g UR                  n	U R                  c=  U	R                  n
UR                  R                  R                  5       nUR                  nOaU R                  R                  n[        U" U	5      5      n
[        U" UR                  5      5      R                  5       n[        U" U5      5      n[        XX-   5      nU(       + nUR                  R!                  U(       a  UOU* 5      nU(       a  U(       d  U(       a  U(       a  U R#                  XUU-   5        g g g )N)      rN   r  )ry   r   r  r  last_leader_pointr   r  landing_gap_sizer   r   vec2r   
orthogonalrH  r   r   r   add_dxf_line)r   r   r   has_left_underlinehas_right_underlineconnection_pointr   r  lengthstartstart2dup2dcp2drH  is_leftis_rightr^  s                    rF   r\  RenderEngine.add_text_underline'  sj   ""=!66)C"88IE"&9!336H6PP**666D= 88jjG'',,779D#((Dxx((H8E?+G!5!567BBDD!123D'w~F;##--ffWM*,.40GH -HrE   c                B   U R                   R                  nUc  g U R                  S:H  nU R                  S:H  nU(       d  U(       d  g U R                  u  pVUS:  a  g UR
                  nUR                  nUR                  R                  US-  5      n	Xy-
  n
Xy-   nU R                  c  [        XU5      nO5U R                  R                  n[        U" U5      U" U
5      U" U5      5      nU(       + nU(       a  U(       d  U(       a  U(       a  U R                  X5        g g g )N
   r  rJ   )ry   r   r  r  r  rc  r   r   r   r   r   rH  rg  )r   r   r   has_bottom_linehas_top_linerk  r  centerr   line2rl  endbottomrH  tops                  rF   r]  RenderEngine.add_overlineI  s   ""=55;//25<++D=
 ))$$..vz:n88*6#>Fxx((H* (5/8C=F jCLe) 5ACrE   c                    [        U5      nUR                  nUR                  (       a7  U(       a  UR                  U5        UR                  U[	        U5      -   5        U$ UR                  U5        U$ r   )listrc  r  r9  r   )r   r   line_verticesrS   r   	end_points         rF   leader_verticesRenderEngine.leader_verticesi  sb     &,,	++	*OOI(:6(BBC  OOI&rE   c                   U R                   nUS:X  a  g U R                  nUS:X  a  SnU R                  XR                  U5      n[	        U5      S:  a  g [        U5      nUR                  nUR                  nU R                  U R                  U5      5      n	U R                  R                  n
U R                  U	US   UU
US9  U[        X5      -  nUS==   U-  ss'   US:X  a*  [        XUSS  5       H  u  pU R                  XU5        M     g US:X  a;  UR                   (       a  [#        U5      nOUS   US   -
  nU R%                  UXn/US9  g g )	Nr   rJ   F)r   rN  r   rg   r   rH   )tangentsr   )rG   rS   r  r   r   r   r   r  create_arrow_blockr-  ry   rY   	add_arrowr   ziprg  r  r   add_dxf_spline)r   r   r^  rG   rS   r   arrow_directionr   r  rM  
arrow_sizearrow_offsetseend_tangents                  rF   r[  RenderEngine.add_leader_linew  sh   ++!??
!J#33MM: 
 x=1 3H =	ZZ11$2G2G2NO
 LL88
a[% 	 	
 -|0
 
 	|#!Hqrl3!!!	2 4A//08&rlXb\9)7	    rE   c                    XR                   R                  ;  a[  [        R                  " U5      nU[        ;  a  [        R                  n[        R
                  " U R                   R                  U5      nU$ r   )r   blocksr   
arrow_namer,  create_block)r   r   r  s      rF   r  RenderEngine.create_arrow_block  sR    xx&**40J'#11
&&txx
CDrE   c           	         U R                  U5      n[        S[        R                  " SX@R                  S95      nUR                  [        XS95        U R                  R                  U5        g )Nr/   SPLINErD  )r  )	r2  r
   r   r   r   apply_construction_toolr   r   r9  )r   
fit_pointsr  r   r1  splines         rF   r  RenderEngine.add_dxf_spline  s_     **51KKW((C
 	&& ?	
 	V$rE   c                    U R                  U5      nXS'   X$S'   U R                  R                  [        R                  " SX@R
                  S95        g )Nrl  ry  LINErD  )r2  r   r9  r   r   r   )r   rl  ry  r   r1  s        rF   rg  RenderEngine.add_dxf_line  sE    **51 KK7A	
rE   c                   U R                  U5      nXS'   U R                  bE  U R                  R                  U5      nU R                  R                  U5      nU R                  US'   X&S'   UR                  S-   US'   XFS'   XFS'   XFS'   U R
                  R                  [        R                  " S	X`R                  S
95        g )Nr   r   r   g     f@r?  r@  rA  rB  rC  rD  )
r2  r   rH  r   	angle_degr   r9  r   r   r   )r   r   rN  r   rg   r   r1  s          rF   r  RenderEngine.add_arrow  s     **5188xx((2H)))4I#'>>GK $'11E9
!!!KKW((C	
rE   )r  rW   r   r  ry   r   r  r   r   r   rS   r  ra   r   r   r   r   rG   r  r   r   r   r   r  rg   r   r  )r   r(   r   r*   )r   r~   )r   ztuple[float, float])r   zlist[DXFGraphic])r   r   )r  intr   r   r   )r   Optional[int]r   rQ  )r   None)r   r-   )r   r#   F)r   r#   r  
list[Vec3]r   r  )r   r#   r^  r$   )r   r   r   r   )NN)r  r  r  zOptional[Iterable[UVec]]r   r  )rl  r   ry  r   r   r  )
r   r   rN  r   r   r   rg   floatr   r  )r@   rA   rB   rC   r   propertyr  r  r  r  r   r   r-  r2  r!  r5  r:  r6  rL  r"  r\  r]  r  r[  r  r  rg  r  rD   r?   rE   rF   r   r   R  s*   +
Z $ $ . . . . ' '"%$%".@,.& ID*B IN 1;	+Z .2#	%% +% 	% 


 
 	

 
 
rE   r   c                  $    \ rS rSrSrSrSrSrSrg)r8   i  zThe leader type.r   rH   rJ   r?   N)	r@   rA   rB   rC   __doc__nonestraight_linessplinesrD   r?   rE   rF   r8   r8     s    DNGrE   r8   c                      \ rS rSrSr\R                  " 5       r\R                  " 5       r\R                  " 5       r	\R                  " 5       r
Srg)r5   i  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.
r?   N)r@   rA   rB   rC   r  enumautoleftrightr{  rz  rD   r?   rE   rF   r5   r5     s5     99;DIIKE
))+CYY[FrE   r5   c                  @    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrg)r6   i  z&The horizontal leader connection type.r  r   rH   rJ   r   rL   ra  rb     rN   r?   N)r@   rA   rB   rC   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_allrD   r?   rE   rF   r6   r6     s>    0HON&'##$ '($rE   r6   c                  $    \ rS rSrSrSrSrSrSrg)r7   i  z$The vertical leader connection type.r   	   rt  r?   N)	r@   rA   rB   rC   r  r  rw  center_overlinerD   r?   rE   rF   r7   r7     s    .HFOrE   r7   c                  $    \ rS rSrSrSrSrSrSrg)r9   i  z"The :class:`MText` alignment type.rH   rJ   r   r?   N)	r@   rA   rB   rC   r  r  rw  r  rD   r?   rE   rF   r9   r9     s    ,DFErE   r9   c                       \ rS rSrSrSrSrSrg)r:   i  z"The :class:`Block` alignment type.r   rH   r?   N)r@   rA   rB   rC   r  center_extentsinsertion_pointrD   r?   rE   rF   r:   r:     s    ,NOrE   r:   c                  L    \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   SS jrS	rg
)ConnectionBoxi$  z\Contains the connection points for all 4 sides of the content, the
landing gap is included.
r   r  r  r{  rz  c                    U[         R                  :X  a  U R                  $ U[         R                  :X  a  U R                  $ U[         R                  :X  a  U R                  $ U R                  $ r   )r5   r  r  r{  rz  )r   sides     rF   r{   ConnectionBox.get/  sS    >&&&99^)))::^'''88O{{rE   r?   N)r  r5   r   r   )r@   rA   rB   rC   r  __annotations__r{   rD   r?   rE   rF   r  r  $  s"     JK	ILrE   r  c                    [         R                  " U R                  5      (       dE  [        U R                  5      n[	        UR                  U R                  5      5      nUR                  $ g)z)Returns the ocs rotation angle of the UCSr  )r   r   uzr   r   rH  uxangle)ucsr   x_axis_in_ocss      rF   ocs_rotationr  9  sH    >>#&&!!#&&kS\\#&&12"""rE   c                     \ rS rSrSS jr\R                  S 5       rS r\R                  SS j5       r	\R                        SS j5       r
\R                  SS j5       r\R                  S S j5       r\S!S	 j5       r\S"S
 j5       r\S#S j5       rS$S jr  S%   S&S jjr\R(                  \R(                  \R(                  \R(                  4S jrS'S jr\R2                  S\R6                  \R:                  4     S(S jjr  S)   S*S jjr      S+S jr  S,       S-S jjr!S r"S.S jr#S r$        S/S jr%\&      S0S j5       r'Sr(g)1r2   iB  c                   UR                   nUc   S5       eUR                  R                  nUR                  R	                  U5      nUc  [        SU 35      eX l        X@l        Xl        [        [        5      U l        U R                  U5        U R                  R                  R                  U R                  R                  l        g )Nr   zinvalid MLEADERSTYLE handle #)r   rv   r   r   r{   
ValueError_doc_mleader_style_multileaderr   r~  _leadersset_mleader_stylerd  ry   )r   multileaderr   r   r   s        rF   r   MultiLeaderBuilder.__init__C  s    oo= ==--!ll..v6=<VHEFF"	,1'@KA
 	u%##44 	!!2rE   c                    g r   r?   r  s    rF   _init_content MultiLeaderBuilder._init_contentU      rE   c                    g r   r?   r  s    rF   _reset_cacheMultiLeaderBuilder._reset_cacheY  s    rE   c                    g)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.
Nr?   r  s    rF   _build_connection_box(MultiLeaderBuilder._build_connection_box\  s     	rE   c                    g r   r?   )r   r   r?  s      rF    _transform_content_to_render_ucs3MultiLeaderBuilder._transform_content_to_render_ucsd  s     	rE   c                    g r   r?   )r   conversion_factors     rF   _apply_conversion_factor+MultiLeaderBuilder._apply_conversion_factorj  r  rE   c                    g r   r?   r   r  rz  s      rF   _set_base_point"MultiLeaderBuilder._set_base_pointn  r  rE   c                    U R                   $ )z8Returns the :class:`~ezdxf.entities.MultiLeader` entity.)r  r  s    rF   r  MultiLeaderBuilder.multileaderr  s        rE   c                .    U R                   R                  $ )zCReturns the context entity :class:`~ezdxf.entities.MLeaderContext`.)r  ry   r  s    rF   ry   MultiLeaderBuilder.contextw  s       (((rE   c                B    U R                   R                  R                  $ r   )r  ry   rd  r  s    rF   _landing_gap_size$MultiLeaderBuilder._landing_gap_size|  s      ((999rE   c                  ^ ^ U U4S jnUT l         T R                  R                  nUR                  m[        [        R
                  R                  5       5      nU H<  nUR                  U5      (       d  M  UR                  UTR                  U5      5        M>     U" 5         [        TR                  TR                  TR                  5      Ul        T R                  R!                  UR"                  5        T R%                  5         g)ziReset base properties by :class:`~ezdxf.entities.MLeaderStyle`
properties. This also resets the content!
c                 r   > TR                   T R                  l         TR                  T R                  l        g r   )r`   ry   rd  )r   	style_dxfs   rF   copy_style_to_contextCMultiLeaderBuilder.set_mleader_style.<locals>.copy_style_to_context  s'    '0'<'<DLL$,5,F,FDLL)rE   N)r  r  rv   r~  r)   r1  keysis_supportedsetr   r   rr   rt   ru   rd   ry   	set_scalerg   r  )r   r   r  multileader_dxfr  keyr  s   `     @rF   r  $MultiLeaderBuilder.set_mleader_style  s    
	G $++//II	&..3356C++C00##C)>)>s)CD  	-1######.
* 	445rE   c                    U R                   nUR                  R                  nU(       a%  SUR                  l        X$-  UR                  l        OSUR                  l        X-  UR
                  l        g)zSet 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.

rH   r   N)r  rv   rg   rS   rU   ry   rd  )r   rQ   rU   r  rg   s        rF   set_connection_properties,MultiLeaderBuilder.set_connection_properties  sY     &&%%)*KOO&,9,AKOO))*KOO&/:/B,rE   c                   U R                   nU R                  nU[        R                  :X  a  UR                  R
                  Ul        O[        U5      Ul        U[        R                  :X  a  UR                  R                  Ul	        O[        U5      Ul	        U[        R                  :X  a  UR                  R                  Ul        O[        U5      Ul        U[        R                  :X  a  UR                  R                  Ul        O[        U5      Ul        U R                  R                  nUR                  Ul        UR                  Ul        UR                  Ul        UR                  Ul        g)z1Set the connection type for each connection side.N)ry   r  r6   r  rv   r\   left_attachmentr  rh   right_attachmentr7   rk   top_attachmentrl   bottom_attachmentr  )r   r  r  r{  rz  ry   r   rv   s           rF   set_connection_types'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'rE   c                n   [        U5      nUS::  a  [        SU 35      eU R                  nU R                  nUR                  R
                  n X%-  nX$R                  l        UR                  =R                  U-  sl        UR                  U5        U R                  U5        g! [         a    Un N`f = f)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  ry   r  rv   rg   r   rU   r  r  )r   rg   	new_scalery   r  	old_scaler  s          rF   set_overall_scaling&MultiLeaderBuilder.set_overall_scaling  s     %L	7w?@@,,&&OO))		* ) 5 !*%%)::%)$%%&78 ! 	* )	*s   B% %B43B4r   c                r   U R                   n[        R                  " U5      UR                  l        U R
                  R                  R                  U5      nUc  [        SU S35      eUR                  R                  UR                  l
        X5R                  l        [        U5      UR                  l        g)zSet 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_colorrv   rI   r  	linetypesr{   r  r   rK   rM   r  rG   )r   r   r   r   rG   r   	linetype_s          rF   set_leader_properties(MultiLeaderBuilder.set_leader_properties  s      ##(.(?(?(F%II''++H5	6xjBCC-6]]-A-A*(2%"%k"2rE   c                h   US:X  a   U R                   R                  R                  nX R                  R                  l        X R                  l        U(       aE  [
        R                  " U R                  R                  U5      U R                  R                  l	        gU R                  R                  ?	g)zSet 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  rv   rY   r  ry   r   arrow_handler  r  rW   )r   r   sizes      rF   set_arrow_properties'MultiLeaderBuilder.set_arrow_properties  s     3;&&**::D04-'+$6<6I6I		  $7D!!3 !!%%7rE   c                R    U R                   U   R                  [        U5      5        g)ai  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  r9  r~  )r   r  r   s      rF   r[  "MultiLeaderBuilder.add_leader_line  s    " 	d""4>2rE   Nc                @   [        U[        5      (       d   S5       e[        R                  " U5      n[        R
                  " U5      nU R                  5       nUR                  SUR                  UR                  45        U R                  5         U R                  X5        U R                  5         U R                  UR                  UR                  R                   5      UR                  UR"                  R                   5      S9  U R$                  R&                  R)                  5         U R*                  R-                  5        H'  u  pgU R/                  XvUR1                  U5      U5        M)     Ub  U R3                  U5        U R4                  R7                  5         g)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  rz  N)
isinstancer   rF  radiansr   z_rotater  set_rowrI  rJ  $_set_required_multileader_attributesr  _set_attachment_directionr  	transformr  vec3rz  ry   rY  r  r  items_build_leaderr{   _transform_to_wcsr  update_proxy_graphic)r   r   r?  r  mconnection_boxr  leader_liness           rF   buildMultiLeaderBuilder.build2  sA    &$''K)KK'<<)h'335			!fhh)*113--f?&&(^00556;;~4499: 	 	
 	""$"&--"5"5"7D|>3E3Ed3KQO #8?""3'--/rE   c                   U R                   nU(       a  [        R                  U;   =(       d    [        R                  U;   n[        R                  U;   =(       d    [        R
                  U;   nU(       a  U(       a  [        S5      eU(       a  SOSU R                  R                  l	        U(       a  SU R                  R                  l
        g g g )Nz7invalid mix of horizontal and vertical connection typesr   rH   F)r  r5   r  r  r{  rz  r=   r  rv   rj   rS   )r   rY  
horizontalverticals       rF   r)  ,MultiLeaderBuilder._set_attachment_directionT  s    --(--8 $$/  '**g5 %%0  h)M   Q !!; 38!!%%0  rE   c                N    U R                   R                  UR                  5        g r   )r  r*  matrix)r   r  s     rF   r.  $MultiLeaderBuilder._transform_to_wcsh  s    ""3::.rE   c                $   U R                   R                  nU R                  nUR                  S5      nUb  X2R                  ;  aD  UR
                  R                  S5      nUc  [        S5      eUR                  R                  Ul        SUl	        g )NrK   BYLAYERz*required linetype 'BYLAYER' does not existi)
r  rv   r  r{   r   r  r  r   rK   rq   )r   rv   r   r   r   s        rF   r(  7MultiLeaderBuilder._set_required_multileader_attributesl  sy    ""ii12>V<<7}}((3H #MOO)1)<)<C&&0#rE   c                    [         U   n[        5       n[        U R                  R                  5      Ul        [        U R                  R                  R                  5      Ul	        SUl
        SUl        XVl        U[        R                  :X  d  U[        R                  :X  a  SUl        OSUl        U R"                  R                  R$                  (       a"  UR&                  XVR                  * -  -   Ul        OUR&                  Ul        UR+                  UR(                  5      Ul        UR-                  UR                  5      Ul        U R/                  Xa5        U R                  R                  R1                  U5        g )NrH   r   )DOGLEG_DIRECTIONSr#   r   ry   rY  r  r  r  rv   rU   r   has_last_leader_liner   r5   r  r  attachment_directionr  rS   r+  rc  r*  transform_direction_append_leader_linesr9  )r   r2  r  rj  r0  dogleg_directionr   s          rF   r-   MultiLeaderBuilder._build_leaderw  s6    -T24<<//0  %T%6%6%:%:%H%HI#$  	#  0>&&&$.2F2F*F*+F'*+F' **'7'<'< $8$8#88(F$ (8'<'<F$ $%;;v/G/G#H  44V5I5IJ 	!!&7##F+rE   c                    [        U5       HK  u  p#[        5       nX$l        [        R                  " U5      Ul        U R                  R                  U5        MM     g r   )	enumerater$   r  r   r~  r   rZ  r9  )r   r2  r  r   r^  s        rF   rD  'MultiLeaderBuilder._append_leader_lines  sC      )6OE<DJ IIh/DMLL%	  7rE   )r  r  r  r  r  r(   r   r  r   r   r?  r  r   r  r  r  r   r  r  r   rz  r   )r   r(   )r   r%   r   r  )r   r&   r  )rQ   r  rU   r  )rg   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  )r2  list[list[Vec2]]r  r5   rj  r   r0  r   )r   r#   r2  rS  r   r  ))r@   rA   rB   rC   r   abcabstractmethodr  r  r  r  r  r  r  r  ry   r  r  r  r6   r  r7   r  r  r   r   r   LINEWEIGHT_BYBLOCKr8   r  r  r  r[  r3  r)  r.  r(  r-  staticmethodrD  rD   r?   rE   rF   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 &&*:&	& &rE   r2   c                      \ rS rSrS rSS\R                  S4         SS jjrSS jrSS jr	      SS	 jr
SS
 jrS\R                  S4             SS jjrSS jrSrg)r3   i  c                   U R                  5         U R                  nU R                  nU R                  nSUR                  l        S Ul        [        5       nXAl        UR                  R                  Ul
        UR                  R                  Ul        UR                  R                  Ul        UR                  R                  Ul        g )NrJ   )r  ry   r  r  rv   rZ   r   r'   r   default_text_contentr   r[   r   r_   r   text_attachment_pointr   )r   ry   r   r   r   s        rF   r  %MultiLeaderMTextBuilder._init_content  s    ,,#### $%   %		 > >$[[::kk,,!++;;rE   Nr  rQ  c                   U R                   nU R                  nUb%  [        R                  " U5      UR                  l        [        U5      UR                  l        U R                  5         UR                  c   e[        R                  " U5      UR                  l        U(       a'  X0R                  R                  R                  -  Ul        U(       a  U R!                  U5        gg)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  ry   r   r  rv   r_   r  r[  r  r   
text_toolsescape_dxf_line_endingsr   r  rg   r`   _set_mtext_style)r   contentr   r`   r   r   r   ry   s           rF   set_content#MultiLeaderMTextBuilder.set_content  s    ( ##,,%+%<%<U%CGKK",/	N)}}((((2(J(J)
% "-0@0@0D0D0J0J"JG!!%( rE   c                `   U R                   R                  R                  U5      nUbx  UR                  R                  U R
                  R                  l        U R                  R                  c   eUR                  R                  U R                  R                  l	        g [        SU S35      e)Nztext style 'z' does not exist)r  r   r{   rv   r   r  r[   ry   r   r   r  )r   r   r   s      rF   r`  (MultiLeaderMTextBuilder._set_mtext_style  s    		  $$T*6;ii6F6FD!!3<<%%111.3ii.>.>DLL+|D61ABCCrE   c           
       ^^^^^ SUUU4S jjn    SUU4S jjnU R                   nUR                  m[        T[        5      (       d   S5       e[	        UR
                  5      n[	        UR                  5      nUR                  mUR                  m[        U R                  5      n[        R                  " UR                  5      (       a/  [        R                  " U5      nUR                   mUR"                  mO[        R$                  " U5      u  mmU" 5       nUT-   ST-  -   n	X-   S-  n
['        [)        X" U5      5      [)        X" U5      5      [)        U
T5      [)        U
T* T-
  5      S9$ )	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                 z   > Tc   eT* n TR                   S:X  a  T* S-  T-
  n U $ TR                   S:X  a  T* T-
  n U $ )NrJ         ?r   r   )rI  gapr   r   s    rF   
get_left_xAMultiLeaderMTextBuilder._build_connection_box.<locals>.get_left_x  sW    $$$A!#FSL3& H A%FSLHrE   c                  > T[         -  nU [        R                  :X  a  T* S-  $ U [        R                  :X  a  T* S-  $ U [        R                  :X  a	  T* TS-  -   $ U [        R
                  [        R                  4;   a  T* U-
  $ U [        R                  [        R                  [        R                  4;   a  T* U-
  $ g)Nrh  r  )
UNDERLINE_DISTANCE_FACTORr6   r  r  r  r  r  r  r  r  )
connectionunderline_distancer`   r  s     rF   vertical_connection_heightQMultiLeaderMTextBuilder._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rE   zundefined MTEXT contentg       @rh  r  r  r{  rz  rO  )ro  r6   r   r  )ry   r   r$  r'   r6   r
  r  r`   rd  r   r  r^  has_inline_formatting_codesr    r   
mtext_sizetotal_widthtotal_heightr  r  r   )r   rk  rq  ry   r
  r  r   r  left_xright_xcenter_xr`   rj  r  r   r   s              @@@@@rF   r  -MultiLeaderMTextBuilder._build_connection_box  s\   	 		,		 	. ,,%++F-FF+.w/F/FG/0H0HI))&&
 D--.11&++>>''/D$$E&&F%<<VDME65.39,$+ f8IJw :;K LMXs#6'C-0	
 	
rE   c                    U R                   R                  nUc   e[        Ul        [	        U5      Ul        [        R                  " U5      Ul        X#l	        g r   )
ry   r   r   r   r   r   r   rotater   r?  )r   r   r?  r   s       rF   r  8MultiLeaderMTextBuilder._transform_content_to_render_ucsC  sG     ""    F|%}}X6!rE   c                \    U R                   R                  nUc   eUR                  U5        g r   )ry   r   apply_conversion_factor)r   r  r   s      rF   r  0MultiLeaderMTextBuilder._apply_conversion_factorN  s,    ""   %%&78rE   c                   UnUb  Xt-  n[        U[        5      (       a  [        R                  nO0UR                  S::  a  [        R
                  O[        R                  nU R                  XS9  [        U R                  R                  R                  5      n	U R                  5       n
[        U[        5      (       ar  SnUR                  S::  a(  [        R
                  nU
R
                  R                  * nO'[        R                  nU
R                  R                  * nU R!                  UUS9  O[        U[        5      (       at  Sn	SnUR                  S:  a(  [        R"                  nU
R"                  R                  * nO'[        R$                  nU
R$                  R                  * nU R!                  UUS9  O['        S5      eU/nUb  UR)                  X#-   5        U R+                  X5        [-        U R.                  R                  R0                  5      nU R2                  nX'-   n[4        U   nU	(       a	  UUU-   -  nO
[7        5       nUU-   [7        X5      -   nU R9                  UUS9  g)	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  ri  )r  r  F)r{  rz  zinvalid connection type)r  )r$  r7   r9   rw  rI  r  r  rb  r~   r  rv   rS   r  r6   r5   rJ  r  rz  r{  r  r9  r[  r  r  rU   r  r@  r   r3  )r   ra  targetsegment1segment2connection_typer  offsetr   rS   r1  move_text_xr  move_text_ypointsrU   rj  rc  rE  last_segmentr   s                        rF   quick_leader$MultiLeaderMTextBuilder.quick_leaderS  s;   @ Fo'9::%,,I (.xx3##M<N<N  	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&+,T* d//33AAB$$"O,T2+}s/BCL6L,tK/MM 	 	

6s
#rE   c                    U R                   R                  R                  S:X  a  XR                  l        g X R                  l        g r   )r  rv   rj   ry   
base_pointr  s      rF   r  'MultiLeaderMTextBuilder._set_base_point  s0      ::a?&*LL#&,LL#rE   r?   )
ra  r   r   z Optional[Union[int, colors.RGB]]r`   r  r   r9   r   r   )r   r   rK  rL  rM  )ra  r   r  r   r  r   r  zOptional[Vec2]r  z/Union[HorizontalConnection, VerticalConnection]r  rR  r   r  rN  )r@   rA   rB   rC   r  r9   r  rb  r`  r  r  r  r6   r  r  r  rD   r?   rE   rF   r3   r3     s    <8  #0#5#5#)#)
#) #) !#) #)JDD
L	"	"&+	"		"9 $( !33!a$a$ a$ 	a$
 !a$
a$ a$ 
a$F-rE   r3   c                     ^  \ rS rSrSU 4S jjrS rU 4S jr\SS j5       r\SS j5       r	SS jr
SS jrSS	 jr\R                  S
\R                   4     SS jjrSSS jjrSS jrSrU =r$ )r4   i  c                P   > [         TU ]  U5        S U l        [        5       U l        g r   )superr   _block_layoutr   _extents)r   r  	__class__s     rF   r    MultiLeaderBlockBuilder.__init__  s!    %6:#rE   c                   U R                  5         U R                  nU R                  nSUR                  l        S Ul        [        5       nX1l        UR                  R                  Ul        UR                  R                  UR                  -  Ul
        UR                  R                  Ul        UR                  R                  Ul        g )NrH   )r  ry   r  rv   rZ   r   r"   r   rb   rd   rg   re   r?  rc   r   )r   ry   r  r   s       rF   r  %MultiLeaderBlockBuilder._init_content  s    ,,'' ()$ $/OO$G$G!!oo887==H$77!oo11rE   c                N   > [         TU ]  5         S U l        [        5       U l        g r   )r  r  r  r   r  )r   r  s    rF   r  $MultiLeaderBlockBuilder._reset_cache  s    !#rE   c                   U R                   b  U R                   $ U R                  R                  n[        U[        5      (       d   S5       eUR
                  nU R                  R                  R                  U5      nUc  [        SU 35      eUR                  R                  nU R                  R                  R                  U5      nUc  [        SU S[        U5       S35      eXPl         U$ )zReturns the block layout.undefined BLOCK contentzinvalid BLOCK_RECORD handle #zBLOCK 'z' defined by z
 not found)r  ry   r   r$  r"   rb   r  r   r{   r  rv   r   r  r   )r   r   r   r   r   block_layouts         rF   r  $MultiLeaderBlockBuilder.block_layout  s     )%%%""%++F-FF+**yy))--f5<VHEFF$$yy''++D1$}S->,?zJ  *rE   c                    U R                   R                  (       dW  SSKJn  U R                  nUR                  S U 5       5      nUR                  (       d  UR                  [        /5        X0l         U R                   $ )z&Returns the bounding box of the block.r   )bboxc              3  P   #    U  H  oR                  5       S :w  d  M  Uv   M     g7f)ATTDEFN)dxftype).0r  s     rF   	<genexpr>2MultiLeaderBlockBuilder.extents.<locals>.<genexpr>  s       #'a99;(+B<s   &	&)r  has_datar;   r  r  extentsextendr   )r   r  r  r  s       rF   r  MultiLeaderBlockBuilder.extents  sb     }}%%",,Lll #'# G ##y)#M}}rE   c           
     B   U R                   R                  n[        U[        5      (       d   S5       eU R                  R
                  R                  nU R                  nU R                  nUR                  R                  nUR                  R                  nUR                  R                  S-  U-  nUR                  R                  S-  U-  nUR                  R                  U-  n	UR                  R                  U-  n
UR                  R                  U-  U	-
  nUR                  R                  U-  U
-
  nU[        R                   :X  a  [#        U* U* S5      Ul        SnSn['        [)        X-
  U5      [)        X-   U5      [)        XU-   5      [)        XU-
  5      S9$ )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.
r  rh  r   r  rs  )ry   r   r$  r"   r  rv   rf   r  r  rg   rI  rJ  r  r  rw  r:   r  r   r   r  r   )r   r   rf   r  r  sxsywidth2height2base_xbase_yrz  center_ys                rF   r  -MultiLeaderBlockBuilder._build_connection_box  sk    ""%++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X'12W"45	
 	
rE   c                    U R                   R                  n[        U[        5      (       d   S5       e[        Ul        UR                  R                  U5      [        U5      -   Ul        X#l	        g Nr  )
ry   r   r$  r"   r   r   r   r}  r   r?  )r   r   r?  r   s       rF   r  8MultiLeaderBlockBuilder._transform_content_to_render_ucs"  sU    ""%++F-FF+ ||**84tF|C!rE   c                    U R                   R                  n[        U[        5      (       d   S5       eUR	                  U5        g r  )ry   r   r$  r"   r  )r   r  r   s      rF   r  0MultiLeaderBlockBuilder._apply_conversion_factor)  s9    ""%++F-FF+%%&78rE   rs   c                   U R                   nU R                  R                  R                  U5      nUc  [	        SU S35      eUR
                  UR                  l        [        R                  " U5      UR                  l	        [        X3U5      UR                  l        [        U5      UR                  l        U R                  5         g)zSet 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  r{   r  rb   rv   r   r  rc   r   rd   r  rf   r  )r   r   r   rg   r   r   r   s          rF   rb  #MultiLeaderBlockBuilder.set_content.  s      ##		  $$T*=0a899*/*C*C'"("9"9%"@)-eE)B&,/	N)rE   c                D   U R                   nU R                  R                  n[        UR	                  5       5       Ha  u  pgXR
                  R                  :X  d  M   UR                  [        UR
                  R                  U[        U5      [        U5      S95          g   g)a  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)r  r  rK  rH  attdefsrv   rR  r9  r!   r   r  r   )r   rR  r    r   r  rK  r  rV  s           rF   set_attribute%MultiLeaderBlockBuilder.set_attributeJ  s     (())77&|';';'=>MEjjnn$$$%zz00##El Y	  ?rE   c                $    XR                   l        g r   )ry   r  r  s      rF   r  'MultiLeaderBlockBuilder._set_base_pointc  s    "&rE   )r  r  rJ  )r   z'BlockLayout')r   r   rK  )r   r   r?  r  rM  )r   r   r   rP  rg   r  )rs   )rR  r   r    r   r   r  rN  )r@   rA   rB   rC   r   r  r  r  r  r  r  r  r  r   r   r:   r  rb  r  r  rD   __classcell__)r  s   @rF   r4   r4     s    &
2(&
  *  
B"9 )/ // & 	82' 'rE   r4   r  )r   r(   r   zIterator[DXFGraphic])r   r(   r   r*   r   rn   )r   r   r   r*   r   r0   )r   r  r   r   )r   r  r   ztuple[int, Optional[int]])r   r.   r   r'   rg   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
   rT  rF  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   rn  DXFErrorr=   r   rn   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  r{  rz  r@  r6   r7   r9   r:   r  r  ABCr2   r3   r4   r?   rE   rF   <module>r     sP   #       # !     #  + 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'rE   