
    Og                    p   d dl mZ d dlmZmZmZmZmZ d dlZd dl	Z	d dl
mZmZmZmZmZmZ d dl
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 d dl m!Z! d dl"m#Z#m$Z$ erd dl%m&Z& d dl"m'Z' d dl(m)Z)  G d de      Z*dZ+dZ,e,dz   Z-e,dz   Z.dZ/d2dZ0d3dZ1	 	 	 	 d4	 	 	 	 	 	 	 	 	 	 	 d5dZ2d6dZ3 G d d      Z4 G d d      Z5 G d d       Z6 G d! d"      Z7 G d# d$      Z8 G d% d&e8      Z9 G d' d(      Z: G d) d*      Z;d7d+Z<	 	 	 	 	 	 	 	 d8d,Z=d9d-Z>	 	 	 	 	 	 	 	 	 	 	 	 d:d.Z?d;d/Z@d<d0ZAd=d1ZBy)>    )annotations)TYPE_CHECKINGIterableOptionalAnycastN)Vec3Vec2UVecConstructionLineConstructionBoxConstructionArc)UCSPassTroughUCSxroundZ_AXIS)const)TextEntityAlignment)options)DXFValueErrorDXFUndefinedBlockError)suppress_zeros)ARROWS)DimStyleOverride	Dimension)Drawing)	Textstyle)GenericLayoutTypec                  V     e Zd ZdZ edd      dddddf	 	 	 	 	 	 	 	 	 	 	 d fdZ xZS )TextBoxzText boundaries representation.r           c                B    t         |   ||d|z  z   |d|z  z   |       y )N       @)super__init__)selfcenterwidthheightanglehgapvgap	__class__s          Z/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/render/dim_base.pyr%   zTextBox.__init__'   s*     	t!3VcDj5H%P    )r'   r
   r(   floatr)   r0   r*   r0   r+   r0   r,   r0   )__name__
__module____qualname____doc__r
   r%   __classcell__)r-   s   @r.   r    r    $   sl    ) Aqz	Q	Q 	Q 		Q
 	Q 	Q 	Q 	Qr/   r       ±z\A{align};{txt}{{\H{fac:.2f}x;z{tol}}}z\S{upr}^ {lwr};}}z {{\H{fac:.2f}x;\S{upr}^ {lwr};}}c                    | t        |       S y N)r
   )vs    r.   OptionalVec2r:   :   s    }Awr/   c                    | dk  ry| dkD  ryy)Nr!   -r   +  )values    r.   	sign_charrA   A   s    s{	r/   c                    |t        | |      } |d}|dz  }ndt        |      z   dz   }|j                  |       }t        |dz        }t        |dz        }t	        |||      }|dk7  r|j                  d|      }|S )Nz{:f}   z{:.zf}   .)r   strformatboolr   replace)	r@   dimrnddimdecdimzindimdsepfmttextleadingpendings	            r.   format_textrR   J   s     uf%~ !c&k!D(::eD6A:G6A:G$1D#~||C)Kr/   c                p    d|v r$|j                  ddd      }|j                  |       S t        d| d      )N<>z{}   zInvalid dimpost string: "")rI   rG   r   )rO   dimpostrN   s      r.   apply_dimpostrX   e   s?    woodD!,zz$7yBCCr/   c                  v    e Zd Z	 	 	 d	 	 	 	 	 	 	 ddZedd       Zd Zd ZddZd Z	ddZ
ddZdd	Zdd
Zy)	Tolerancec                   || _         || _        |j                  }t         |dd            | _        d| _        | j                  st         |dd            | _         |dd      | _        |j                         | _        d| _	         |dd	      | _
         |d
d	      | _         |dd      | _         |dd      | _         |dd      | _        d| _        d	| _        d	| _        d| _        d| _        || j                  z  | j                  z  | _        | j                  r| j+                          y | j
                  r| j-                          y y )Ndimtolr   Fdimlimdimtfacg      ?g?dimtmr!   dimtpdimtdec   dimtoljdimtzin )text_width_factor	dim_scalegetrH   has_tolerance
has_limitstext_scale_factorget_decimal_separatortext_decimal_separatorline_spacingminimummaximumdecimal_placesvalignr   rO   text_height
text_width
text_upper
text_lowerchar_heightinit_toleranceinit_limits)r&   	dim_style
cap_heightwidth_factorrg   rh   s         r.   r%   zTolerance.__init__n   s@    "."mm "#h"23!!"3x#34DO ),Is(;&/&E&E&G# $( "'3/ "'3/ $'y!#4 y!, $'y!#4	"%!$!!",t/E/E"E"V!__ r/   c                6    | j                   xs | j                  S r8   ri   rj   r&   s    r.   enabledzTolerance.enabled   s    !!4T__4r/   c                     d| _         d| _        y NFr~   r   s    r.   disablezTolerance.disable   s    "r/   c                   | j                   | j                  k(  r=| j                  | _        | j	                  | j
                  | j
                        | _        nV| j                  | j                  | j                  z  z   | _        | j	                  | j                  | j                        | _        | j                  | j                  | j                          y r8   )ro   rp   rw   rs   get_text_widthrO   rt   rn   ru   rv   update_tolerance_textr   s    r.   rx   zTolerance.init_tolerance   s     <<4<<'#//D"11$))TYYGDO  $//43C3CdFWFW3WXD"11$//4??SDO""4<<>r/   c                   ||k(  r't         | j                  t        |            z   | _        y t	        |      | j                  t        |            z   | _        t	        |dz        | j                  t        |            z   | _        y )N)
PLUS_MINUSrR   absrO   rA   ru   rv   )r&   	tol_upper	tol_lowers      r.   r   zTolerance.update_tolerance_text   sn    	!"T%5%5c)n%EEDI'	2T5E5Ec)n5UUDO'	B7$:J:JI; DOr/   c                Z    | j                   | j                  | j                  z  z   | _        y r8   )rw   rs   rn   r   s    r.   ry   zTolerance.init_limits   s(      ++t/?/?$BSBS/STr/   c                ^    t        |d| j                  | j                  | j                        S )zuRounding and text formatting of tolerance `value`, removes leading
        and trailing zeros if necessary.

        N)r@   rJ   rK   rL   rM   )rR   rq   r   rm   r&   r@   s     r.   rR   zTolerance.format_text   s2     &&&&//
 	
r/   c                v    t        t        |      t        |            }| j                  | j                  z  |z  S )zCReturns the text width of the tolerance (upr/lwr) in drawing units.)maxlenrs   rf   )r&   uprlwrcounts       r.   r   zTolerance.get_text_width   s4     CHc#h'$"8"885@@r/   c                   | j                   rt        t        | j                        d      }t	        |d      }| j
                  s:t        j                  ||| j                  | j                  | j                        }|S t        j                  ||| j                  | j
                        }|S | j                  r6t        j                  | j                  | j                  | j                        }|S )Nr   rb   )aligntxtfacr   r   )r   r   r   tol)r   r   r   )ri   r   intrr   minrO   TOLERANCE_TEMPLATE2rG   rk   ru   rv   TOLERANCE_TEMPLATE1rj   LIMITS_TEMPLATE)r&   rO   r   s      r.   compile_mtextzTolerance.compile_mtext   s    DKK(!,EqME99*11.. 2 (  +11..			 2   __"))OOOO** * D
 r/   c                    || j                   z   }|| j                  z
  }| j                  |      | _        | j                  |      | _        | j                  | j                  | j                        | _        y r8   )rp   ro   rR   ru   rv   r   rt   )r&   measurementupper_limitlower_limits       r.   update_limitszTolerance.update_limits  s^    !DLL0!DLL0**;7**;7--dootOr/   N)      ?r   r   )rz   r   r{   r0   r|   r0   rg   r0   returnrH   )r   r0   r   r0   r@   r0   r   rF   )r   rF   r   rF   r   r0   )rO   rF   r   rF   )r   r0   r   None)r1   r2   r3   r%   propertyr   r   rx   r   ry   rR   r   r   r   r?   r/   r.   rZ   rZ   m   s}      !H#H H 	H
 HT 5 5 ?U
A6Pr/   rZ   c                  B    e Zd ZU ej                  Zded<   ddZdddZy)	ExtensionLinesr   default_lineweightc                   |j                   } |d|      | _         |dd      | _         |dd      | _         |d| j                        | _        t         |dd            | _        t         |dd            | _         |d	d
      |z  | _	         |dd
      |z  | _
        t         |dd            | _         |d| j                        |z  | _        y )Ndimclredimltex1re   dimltex2dimlwedimse1r   dimse2dimexer!   dimexodimfxlondimfxl)rh   color	linetype1	linetype2r   
lineweightrH   	suppress1	suppress2extension_aboveoffsethas_fixed_lengthlength_belowr&   rz   default_colorscalerh   s        r.   r%   zExtensionLines.__init__  s    mmi7
!*b1!*b1"8T-D-DE#C!$45#C!$45
 '*(C&85&@ !3/%7 '+3z1+=&> $'x1E1E#F#Nr/   c                    d| j                   i}|dk(  r| j                  }n |dk(  r| j                  }nt        d|       |r||d<   | j                  | j
                  k7  r| j                  |d<   |S )6Returns default dimension line DXF attributes as dict.r   rU   rb   zinvalid argument num:linetyper   )r   r   r   
ValueErrorr   r   )r&   numattribsr   s       r.   
dxfattribszExtensionLines.dxfattribs/  su    #*DJJ"7!8~~HAX~~H4SE:;;"*GJ??d555$(OOGL!r/   Nrz   r   r   r   r   r0   )rU   )r   r   r   r   	r1   r2   r3   r   LINEWEIGHT_BYBLOCKr   __annotations__r%   r   r?   r/   r.   r   r     s    #666O2r/   r   c                  @    e Zd ZU ej                  Zded<   ddZddZy)DimensionLiner   r   c                0   |j                   } |d|      | _         |dd      |z  | _         |dd      | _         |d| j                        | _        t         |dd            | _        t         |d	d            | _        t         |d
d            | _	        y )Ndimclrddimdler!   dimltypere   dimlwddimsd1r   dimsd2dimtoflrU   )
rh   r   	extensionr   r   r   rH   r   r   has_dim_line_if_text_outsider   s        r.   r%   zDimensionLine.__init__C  s    mmi7
 !$Hc 2U : R0"8T-D-DE  $C!$45  $C!$45 37s9a7H2I)r/   c                    d| j                   i}| j                  r| j                  |d<   | j                  | j                  k7  r| j                  |d<   |S )r   r   r   r   )r   r   r   r   )r&   r   s     r.   r   zDimensionLine.dxfattribs]  sJ    #*DJJ"7=="&--GJ??d555$(OOGL!r/   Nr   r   r   r   r?   r/   r.   r   r   @  s    #666J4r/   r   c                  .    e Zd ZddZedd       ZddZy)Arrowsc                6   |j                   } |d|      | _         |dd      |z  | _        d| _        d| _         |dd      |z  | _        d| _        d| _        | j                  dkD  r| j                  dz  | _        y |j                         \  | _        | _        y )	Nr   dimtszr!   re   dimaszg      ?Fr#   )	rh   r   	tick_sizearrow1_namearrow2_name
arrow_sizer   r   get_arrow_names)r&   rz   r   r   rh   s        r.   r%   zArrows.__init__h  s    mmi/
 #Hc 2U : " "!$Xt!4u!<>>C #nns2DO ))+  r/   c                     | j                   dkD  S Nr!   )r   r   s    r.   	has_tickszArrows.has_ticks~  s    ~~##r/   c                    d| j                   iS Nr   )r   r   s    r.   r   zArrows.dxfattribs  s    $$r/   Nrz   r   r   r   r   r0   r   r   )r1   r2   r3   r%   r   r   r   r?   r/   r.   r   r   g  s     ,, $ $%r/   r   c                      e Zd Z	 	 	 	 	 	 ddZed        Zed        ZddZedd       ZddZ	ddZ
ddZddd	Zdd
Zej                  dd       Zej                  dd       Zy)Measurementc                r   d| _         d| _        d| _        |j                  }|j                  }|J d       t        |j                  dd             | _        |j                  dd      | _        |j                  dd      | _	        |j                  dd      | _
        |j                  }d	| _        |j                  d
d       | _         |dd      | _         |dt         j"                        }||j$                  j&                  vrd}|| _        t+        ||      }t-        ||      |z  | _        |j                  dd      | _        |j2                  j                  | _         |dd      |z  | _        |j                  dd       | _        | j8                  | _         |d|      | _         |dd       | _         |dd      | _          |dd      | _!         |dd      | _"         |dd      | _#        |jI                         | _%         |dd      | _&         |dd      | _'         |dd      | _(        d | _)         |d!d      | _*         |d"d      | _+         |d#d      | _,         |d$d      | _-        | j                  d uxr | jZ                  dk(  | _.         |d%d      | _/         |d&d      | _0        tc         |d'd            | _2         |d(d      | _3         |d)d      | _4         |d*d      | _5         |d+d      | _6        d| _7         |d,d      dk(  rd-| _7        d| _8        ts        dd      | _:        d| _;        d| _<        y ).Nr!   re   valid DXF document requireduser_locationrelative_user_locationFtext_shift_htext_shift_v   horizontal_directiondimlfacr   dimtxstyStandardr(   dimgapg      ?text_rotationdimclrtrJ   rK   rb   dimadecrL   rC   dimazinrW   dimtfillr   dimtfillclrrU   g?dimjustdimtaddimtvpdimtmovedimtihdimtohdimtixdimatfitdimlunitdimfracdimaunit	dimarcsymT)=	raw_valuer@   rO   	dimensiondocr:   popr   r   r   r   rh   text_attachment_pointget_dxf_attribr   measurement_factorr   default_dimension_text_styletablesstylestext_style_nameget_text_styleget_char_heightrs   rf   dxfstored_dim_texttext_gapuser_text_rotationr   
text_color
text_roundrq   angular_decimal_placesr   angular_suppress_zerosrl   decimal_separatortext_post_process_format	text_filltext_fill_colortext_box_fill_scaletext_haligntext_valigntext_vertical_positiontext_movement_rule
has_leadertext_inside_horizontaltext_outside_horizontalrH   force_text_insidetext_fitting_rulelength_unitfraction_formatangle_unitshas_arc_length_prefixtext_is_outsider
   text_locationis_wide_texthas_upside_down_correction)	r&   rz   r   r   r  r  rh   
style_name
text_styles	            r.   r%   zMeasurement.__init__  sh    !$
	''	mm= == .:MM/40.

 -6MM$e-
# $-==#E#,==#E mm +," 6?5M5M"D6
!
 *-Y)< j'*N*NO
SZZ...#J$.#C4
"1)Z"H5"P(2(A(A'3(O$-MM$6$6  #8U3e; *3)A)A/SW)X$($;$;"9e4+.x+>#&x#3+.y!+<# $'x#3 ,/y!+<# '0&E&E&G-0B-?%
 "*a0$'q$9*-  !$Iq 1 !$Ha 0 .13-?# (+:q'9 d*Kt/F/F!/K 	 -0!,<# .11-=$ (,C!,<'= '**a&8 !$J 2 %(	1$5 !$J 2+0"{A!#)-D& &+ $(1: #( 16'r/   c                    | j                    S r8   )r7  r   s    r.   text_is_insidezMeasurement.text_is_insideR  s    ''''r/   c                H    t        | j                  xs | j                        S r8   )rH   r   r   r   s    r.   has_relative_text_movementz&Measurement.has_relative_text_movementV  s    D%%:):):;;r/   c                p    t        | j                  | j                  f      }||j                  |      z  }|S )a5  Add `self.text_shift_h` and `sel.text_shift_v` to point `location`,
        shifting along and perpendicular to text orientation defined by
        `text_rotation`.

        Args:
            location: location point
            text_rotation: text rotation in degrees

        Returns: new location

        )r
   r   r   
rotate_deg)r&   locationr   	shift_vecs       r.   apply_text_shiftzMeasurement.apply_text_shiftZ  s9     $++T->->?@	I((77r/   c                D    | j                   dk(  ry| j                   dk(  ryy)z|Returns vertical placement of dimension text as 1 for above, 0 for
        center and -1 for below dimension line.

        r   rD   r   rU   )r+  r   s    r.   vertical_placementzMeasurement.vertical_placementj  s)     q "r/   c                    | j                   dk(  r| j                  | j                  z  S | j                  dz  | j                  z   | j                  z  S )zReturns the vertical distance for dimension line to text midpoint.
        Positive values are above the line, negative values are below the line.

        r   r#   )r+  rs   r,  r  rG  r   s    r.   text_vertical_distancez"Measurement.text_vertical_distancew  sN    
 q ##d&A&AAA$$s*T]]:d>U>UUUr/   c                P    | j                   | j                  z  }t        |      |z  S )z;
        Return width of `text` in drawing units.

        )rs   rf   r   )r&   rO   
char_widths      r.   rt   zMeasurement.text_width  s)     %%(>(>>
4y:%%r/   c                v    | j                   }|dk(  ry| j                  |      }|r|j                  d|d      S |S )zrCreate dimension text for `measurement` in drawing units and applies
        text overriding properties.

        r>   re   rT   rU   )r  rR   rI   )r&   r   rO   formatted_measurements       r.   text_overridezMeasurement.text_override  sG    
 ##3; $ 0 0 =<<&;Q??$$r/   c                V    t        |      | _        |rdnd| _        || _        d| _        y)R  Set user defined dimension text location. ezdxf defines a user
        defined location per definition as 'outside'.

        Args:
            location: text midpoint
            leader: use leader or not (movement rules)
            relative: is location absolute (in UCS) or relative to dimension
                line center.

        rU   rb   TN)r
   r   r-  r   r7  r&   rC  leaderrelatives       r.   location_overridezMeasurement.location_override  s,     "(^'-!1&.##r/   c                    d| j                   iS r   )r!  r   s    r.   r   zMeasurement.dxfattribs  s    ))r/   c                     y)z\Update raw measurement value, scaled measurement value and
        dimension text.

        Nr?   r&   raw_measurement_values     r.   updatezMeasurement.update      r/   c                     y)kRounding and text formatting of `value`, removes leading and
        trailing zeros if necessary.

        Nr?   r   s     r.   rR   zMeasurement.format_text  rZ  r/   Nr   )rC  r
   r   r0   r   r
   r   r0   )rO   rF   r   r0   )r   r0   r   rF   FFrC  r   r   r   r   rX  r0   r   r   r   )r1   r2   r3   r%   r   r>  r@  rE  rG  rI  rt   rN  rT  r   abcabstractmethodrY  rR   r?   r/   r.   r   r     s    I6#I6 I6 	I6V ( ( < <  
 
V&%$ * 	  	 r/   r   c                      e Zd ZddZddZy)LengthMeasurementc                z    || _         || j                  z  | _        | j                  | j                        | _        y)z[Update raw measurement value, scaled measurement value and
        dimension text.
        N)r  r  r@   rN  rO   rW  s     r.   rY  zLengthMeasurement.update  s3     /*T-D-DD
&&tzz2	r/   c                    t        || j                  | j                  | j                  | j                        }| j
                  rt        || j
                        }|S )r\  )rR   r"  rq   r   r%  r&  rX   )r&   r@   rO   s      r.   rR   zLengthMeasurement.format_text  sU    
 OO""
 (( t'D'DEDr/   Nr`  r   )r1   r2   r3   rY  rR   r?   r/   r.   rd  rd    s    3r/   rd  c                      e Zd ZdZ	 	 	 	 	 	 ddZe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dZy)Geometryz
    Geometry layout entities are located in the OCS defined by the extrusion
    vector of the DIMENSION entity and the z-axis of the OCS
    point 'text_midpoint' (group code 11).

    c                   |j                   J d       || _        |j                   | _         | j                   j                  | _        | j                  dk\  | _        | j                  dk\  | _        || _        |j                  | _        | j                  j                  t               | _
        || _        t               | _        y )Nr   AC1015AC1021)r  r  
dxfversionsupports_dxf_r2000supports_dxf_r2007ucsuz	extrusioniscloser   requires_extrusionlayoutr    	_text_box)r&   r  ro  rt  s       r.   r%   zGeometry.__init__  s     }}(G*GG($-%MM#xx22(,8(C(,8(C"vv,0NN,B,B6,J(J)/"))r/   c                j    | j                   j                  dkD  xr | j                   j                  dkD  S r   )ru  r(   r)   r   s    r.   has_text_boxzGeometry.has_text_box  s+    ~~##c)Idnn.C.Cc.IIr/   c                    || _         y r8   )rt  )r&   rt  s     r.   
set_layoutzGeometry.set_layout  s	    r/   c                    || _         y r8   )ru  )r&   text_boxs     r.   set_text_boxzGeometry.set_text_box  s	    !r/   c                2    || j                   j                  v S r8   )r  blocksr&   names     r.   	has_blockzGeometry.has_block  s    txx&&r/   c                    | j                   j                  t        |            j                  }| j                   j	                  |      }| j
                  j                  |||||       y r8   )ro  to_ocsr	   vec2to_ocs_angle_degrt  add_arrow_blockref)r&   r  insertsizerotationr   s         r.   r  zGeometry.add_arrow_blockref  sN     f.3388,,X6&&tVT8ZPr/   c                    | j                   j                  t        |            j                  }| j                   j	                  |      |d<   | j
                  j                  |||       y )Nr  )ro  r  r	   r  r  rt  add_blockref)r&   r  r  r  r   s        r.   r  zGeometry.add_blockref  sO     f.33!%!:!:8!D
:  vz:r/   c                   | j                   j                  |      |d<   | j                  j                  ||      }|j	                  | j                   j                  t        |            j                  t        j                         y )Nr  r   )r   )
ro  r  rt  add_textset_placementr  r	   r  r   MIDDLE_CENTER)r&   rO   posr  r   entitys         r.   r  zGeometry.add_text  sl    !%!:!:8!D
:%%dz%B
 	HHOODI&++%33 	 	
r/   c                    | j                   j                  |      |d<   | j                   j                  t        |            j                  |d<   | j
                  j                  ||       y )Nr  r  )ro  r  r  r	   r  rt  	add_mtext)r&   rO   r  r  r   s        r.   r  zGeometry.add_mtext&  sR    
 "&!:!:8!D
:#xxtCy9>>
8dJ/r/   c                    ddi}|D ]S  }| j                   j                  t        |            j                  d      }| j                  j                  ||       U y )Nlayer	Defpointsr!   )zr  )ro  r  r	   rI   rt  	add_point)r&   pointsr   pointrC  s        r.   add_defpointszGeometry.add_defpoints/  s^    [
  	@E xxtE{3;;c;BHKK!!(w!?	@r/   c                J     fd}dfd} j                   j                  |r j                  r j                  }t	        |j                              }t	        |j                  |            }	||	z   }
|
dk(  ry|
dk(  rG|j                  t        |            }t        |      dk(  r|d   }n || \  }}|	rn|} |||       y|j                  t        |            }t        |      dk(  r% ||d   |d         \  }} ||        |||       y ||       y)a  Add a LINE entity to the geometry layout. Removes parts of the line
        hidden by dimension text if `remove_hidden_lines` is True.

        Args:
            start: start point of line
            end: end point of line
            dxfattribs: additional or overridden DXF attributes
            remove_hidden_lines: removes parts of the line hidden by dimension
                text if ``True``

        c                    j                   j                   t        |             j                   t        |            j                         y )Nr  )rt  add_liner	   r  )startendr   r&   r  s     r.   add_line_to_blockz,Geometry.add_line.<locals>.add_line_to_blockM  sA    KK  tE{#((tCy!&&% ! r/   c                R    | z
  j                   |z
  j                   k  r| |fS || fS r8   	magnitude)abr  s     r.   orderz Geometry.add_line.<locals>.orderU  s1    	$$	'<'<<!t!tr/   rb   NrU   r   )r  r
   r  r
   r   tuple[Vec2, Vec2])	ro  r  rw  ru  r   	is_inside	intersectr   r   )r&   r  r  r   remove_hidden_linesr  r  r{  start_inside
end_insideinsideintersection_pointsp1_p2r  s   `` `           @r.   r  zGeometry.add_line:  s3   &		 4#4#4~~Hx11%89LX//45J!J.F{1&.&8&89I%QT9U&V#*+q0,Q/B "#67EB(Uc!"b)&.&8&89I%QT9U&V#*+q0"#6q#9;Nq;QRFB%eR0%b#.%%r/   Nc                .   
 d
 fd} j                   j                  t        |            j                   j                   j                  
|r7 j
                  r+t        ||| j                        D ]  \  }}	 |||	        y |||       y)a  Add a ARC entity to the geometry layout. Removes parts of the arc
        hidden by dimension text if `remove_hidden_lines` is True.

        Args:
            center: center of arc
            radius: radius of arc
            start_angle: start angle in radians
            end_angle: end angle in radians
            dxfattribs: additional or overridden DXF attributes
            remove_hidden_lines: removes parts of the arc hidden by dimension
                text if ``True``

        c           
         j                   j                  t        j                   |             t        j                   |                   y)z!Add ARC entity to geometry block.)r'   radiusstart_angle	end_angler   N)rt  add_arcmathdegrees)ser   	ocs_angle
ocs_centerr  r&   s     r.   r  z!Geometry.add_arc.<locals>.add_arc  sC    KK! LL16,,y|4%   r/   N)r  r0   r  r0   r   r   )ro  r  r	   r  to_ocs_angle_radrw  visible_arcsru  )r&   r'   r  r  r  r   r  r  r  r  r  r  s   ` `  `    @@r.   r  zGeometry.add_arcz  s    .	 	 XX__T&\277
HH--	4#4#4* $
s s#$ K+r/   )r  r   ro  r   rt  z'GenericLayoutType'r   )rt  r   r   r   )r{  r    r   r   )r  rF   r   rH   )
r  rF   r  r
   r  r0   r  r0   r   r   )r  rF   r  r
   r  r0   r   r   rO   rF   r  r
   r  r0   r   r   )r  zIterable[Vec2]r   r   Fr  r
   r  r
   r   r   r   
r'   r
   r  r0   r  r0   r  r0   r   r   )r1   r2   r3   r4   r%   r   rw  ry  r|  r  r  r  r  r  r  r  r  r?   r/   r.   rh  rh    s'   ,, , $	,$ J J"'QQ Q 	Q
 Q 
Q ;; ; 	; 
;

0	@  ">&>& >& 
>&L !1,1, 1, 	1,
 1, 
1,r/   rh  c                      e Zd ZdZ	 	 d	 	 	 	 	 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Zd$dZd%d&dZ	 d'	 	 	 	 	 d(dZ	 	 d)	 	 	 	 	 	 	 	 	 d*dZ	 	 	 	 	 	 	 	 	 	 d+dZd,dZd-dZd.dZd.dZy)/BaseDimensionRendererz,Base rendering class for DIMENSION entities.Nc                   || _         | j                  ||      | _        |  |r|| _        nt	        |      | _        | j                   j
                  j                  | _        | j                   j
                  j                  | _	        | j                  j                  } |dd      | _        t        | j                        dk  rd| _         |dd      | _        | j                  | j                  | j                        | _        | j!                  | j                  | j                        | _        | j%                  | j                  | j                        | _        | j                  j)                  dd      | j&                  _        | j                  j)                  dd      | j&                  _        | j/                  | j                  | j                        | _        | j3                  | j                  | j                        | _        t7        | j                  j8                  | j4                  j8                        | j                  _        y )	Ndimscaler   g&.>dimcenr   suppress_arrow1Fsuppress_arrow2)r  init_geometrygeometryrz   r   r  r   r   r  default_layerrh   rg   r   dim_center_marksinit_measurementr   init_dimension_linedimension_lineinit_arrowsarrowsr  r   r   init_extension_linesextension_linesrx   r   r   rs   )r&   r  ro  overriderh   s        r.   r%   zBaseDimensionRenderer.__init__  s    %.**9c: 	%DN-i8DN
 #'.."4"4":":"&.."4"4":":nn   #J 4t~~% DN &)1%5001C1CT^^T-1-E-E.
 #..t/A/A4>>R !% 2 23De L $ 2 23De L/3/H/H0
 #11$..$BRBRS (+(($((*>*>(
$r/   c                J    ddl m} t        ||xs
 t                |             S )Nr   )VirtualLayout)ezdxf.layoutsr  rh  r   )r&   r  ro  r  s       r.   r  z#BaseDimensionRenderer.init_geometry  s    /	3#9-/=?KKr/   c                \    t        | j                  |j                  |j                  |      S )N)r{   r|   rg   )rZ   rz   rs   rf   )r&   r   r   s      r.   rx   z$BaseDimensionRenderer.init_tolerance  s+    NN"..$66	
 	
r/   c                0    t        | j                  ||      S r8   )r   rz   r&   r   r   s      r.   r  z*BaseDimensionRenderer.init_extension_lines  s    dnneU;;r/   c                0    t        | j                  ||      S r8   )r   rz   r  s      r.   r  z)BaseDimensionRenderer.init_dimension_line  s    T^^UE::r/   c                0    t        | j                  ||      S r8   )r   rz   r  s      r.   r  z!BaseDimensionRenderer.init_arrows   s    dnneU33r/   c                0    t        | j                  ||      S r8   )rd  rz   r  s      r.   r  z&BaseDimensionRenderer.init_measurement  s     >>r/   c           	         | j                   }t        |j                  | j                         |j                  |j
                  xs dd|j                  dz        S )Nr!   g      ?)r'   r(   r)   r*   r+   r,   )r   r    r8  total_text_widthrs   r   r  )r&   r   s     r.   init_text_boxz#BaseDimensionRenderer.init_text_box  sY    &&,,'')**++2s %%,
 	
r/   c                .    t        | j                  |      S r8   )get_required_defpointr  r  s     r.   r  z+BaseDimensionRenderer.get_required_defpoint  s    $T^^T::r/   c                    | j                   j                  |       | j                   j                  s| j                  j	                          y y r8   )r  ry  rm  r   r   )r&   blocks     r.   renderzBaseDimensionRenderer.render  s:     	  ' }}//HH 0r/   c                *   d}| j                   j                  }|rx| j                  j                  r| j                  j                  }|S | j                   j	                  |      }| j                  j
                  r|| j                  j                  z  }|S r   )r   rO   r   rj   rt   ri   )r&   r(   rO   s      r.   r  z&BaseDimensionRenderer.total_text_width"  s|    $$xx""++
  ((33D988))TXX000Er/   c                4    | j                   | j                  dS )z'Returns default DXF attributes as dict.)r  r   )r  r   r   s    r.   default_attributesz(BaseDimensionRenderer.default_attributes.  s      ''''
 	
r/   c                x    | j                   j                  |||       | j                  j                  |||       y)rP  N)rz   set_locationr   rT  rQ  s       r.   rT  z'BaseDimensionRenderer.location_override5  s2     	##Hfh?**8VXFr/   c                    | j                         }|r|j                  |       | j                  j                  ||||       y)a  Add a LINE entity to the dimension BLOCK. Remove parts of the line
        hidden by dimension text if `remove_hidden_lines` is True.

        Args:
            start: start point of line
            end: end point of line
            dxfattribs: additional or overridden DXF attributes
            remove_hidden_lines: removes parts of the line hidden by dimension
                text if ``True``

        N)r  rY  r  r  )r&   r  r  r   r  r   s         r.   r  zBaseDimensionRenderer.add_lineC  s:    & ))+NN:&uc:7JKr/   c                    | j                         }|r|j                  |       | j                  j                  ||||||       y)a  Add a ARC entity to the geometry layout. Remove parts of the arc
        hidden by dimension text if `remove_hidden_lines` is True.

        Args:
            center: center of arc
            radius: radius of arc
            start_angle: start angle in radians
            end_angle: end angle in radians
            dxfattribs: additional or overridden DXF attributes
            remove_hidden_lines: removes parts of the arc hidden by dimension
                text if ``True``

        N)r  rY  r  r  )r&   r'   r  r  r  r   r  r   s           r.   r  zBaseDimensionRenderer.add_arc[  sA    , ))+NN:&FKG=P	
r/   c                L   | j                         }|r|j                  |       |t        v r | j                  j	                  |||||       y|| j                  j                  |      st        d| d      |dk7  r
||d<   ||d<   | j                  j                  ||||       y)ay  
        Add block references and standard arrows to the dimension BLOCK.

        Args:
            name: block or arrow name
            insert: insertion point in UCS
            rotation: rotation angle in degrees in UCS (x-axis is 0 degrees)
            scale: scaling factor for x- and y-direction
            dxfattribs: additional or overridden DXF attributes

        NzUndefined block: "rV   r   xscaleyscale)r  rY  r   r  r  r  r   r  )r&   r  r  r  r   r   r   s          r.   r  z"BaseDimensionRenderer.add_blockrefx  s    & ))+NN:&6>MM,,T65(GT|4==#:#:4#@,/A$q-IJJ|$)!$)!MM&&tVXwGr/   c                $   | j                   }| j                  }| j                         }|j                  |d<   |j                  |d<   |j
                  r|j                  |d<   |j                  |d<   |j                  r4|j                  |d<   |j                  |d<   |j                  dk(  rdnd|d	<   |r|j                  |       |j                  ||||
       y|j                  |d<   |r|j                  |       |j                  ||||
       y)aB  
        Add TEXT (DXF R12) or MTEXT (DXF R2000+) entity to the dimension BLOCK.

        Args:
            text: text as string
            pos: insertion location in UCS
            rotation: rotation angle in degrees in UCS (x-axis is 0 degrees)
            dxfattribs: additional or overridden DXF attributes

        styler   rw   attachment_pointbox_fill_scalebg_fill_colorrU      bg_fillr  r)   N)r  r   r  r  r!  rm  rs   r  r'  r)  r(  rY  r  r  )r&   rO   r  r  r   r  r   r   s           r.   r  zBaseDimensionRenderer.add_text  s    ==&&))+&66&11&&%0%<%<GM"*5*K*KG&'$$,7,K,K()+6+F+F(*5*?*?1*DQ!	"z*tS(wG + 7 7GHz*dCgFr/   c                    d| j                   j                  i}| j                  |||       | j                  |||       y)z
        Add simple leader line from p1 to p2 to p3.

        Args:
            p1: target point
            p2: first text point
            p3: second text point

        r   N)r  r   r  )r&   r  r  p3r   s        r.   
add_leaderz BaseDimensionRenderer.add_leader  s:     t22889
b"j)b"j)r/   c                     y)zTransforms dimension definition points into WCS or if required into
        OCS.

        Can not be called in __init__(), because inherited classes may be need
        unmodified values.

        Nr?   r   s    r.   transform_ucs_to_wcsz*BaseDimensionRenderer.transform_ucs_to_wcs  s     	r/   c                    | j                          | j                  j                  r0| j                  j                  | j                  j
                  _        y y r8   )r  r  rs  rq  r  r  r   s    r.   finalizezBaseDimensionRenderer.finalize  s<    !!#==+++/==+B+BDNN( ,r/   )NN)r  r   ro  Optional[UCS]r  zOptional[DimStyleOverride]r8   )r  r   ro  r  )r   r0   r   r   r   rZ   )r   r   r   r0   r   r   )r   r   r   r0   r   r   )r   r   r   r0   r   r   )r   r   r   r0   r   r   )r   r    )r  rF   r   r
   )r  r   r]  )r   zdict[str, Any]r^  r_  r  r  r   r  )
r  rF   r  r
   r  r0   r   r0   r   r   r  )r  r
   r  r
   r  r
   )r   r   )r1   r2   r3   r4   r%   r  rx   r  r  r  r  r  r  r  r  r  rT  r  r  r  r  r  r  r  r?   r/   r.   r  r    s'   6
 "/3	:
:
 :
 -	:
xL

<;4?
;

G& "LL L 
L< !

 
 	

 
 

: H H  H 	 H
  H 
 HD GD*Cr/   r  c                P    | |z
  j                   | |z
  j                   kD  r||fS ||fS r8   r  )r  r  r  s      r.   order_leader_pointsr    s0    
Rb2g0002v2vr/   c                    |j                   \  }}}}|j                  |      }|j                  |      }|}	||z
  j                  |      }
| j                  |      | j                  |      kD  r|}	|
 }
|	|
z   |	fS )zFReturns the leader points of the "leg" for a vertical centered leader.)cornerslerp	normalizedistance)target_pointr{  
leg_lengthc0c1c2c3left_centerright_centerconnection_point
leg_vectors              r.   get_center_leader_pointsr    s     %%NBB ''"+K772;L"r'$$Z0J[)L,A,A,,OO' [

 j(*:::r/   c                    | j                   }|j                  |      rt        |j                  |            S t	        j
                  |      r8   )r  hasattrr
   rh   r   DXFMissingDefinitionPoint)dimr  r  s      r.   r  r    s;    
''C
{{4CGGDM""

)
)$
//r/   c                   g }|t         j                  z  }|t         j                  z  }t        | |t        j                  |      t        j                  |            }|j	                         D ]w  }|j                  |      D ]a  }|| z
  j                  t         j                  z  }	|s|j                  |	       7t        j                  |d   |	      rQ|j                  |	       c y t        |      dk(  rJ||kD  r'|D 
cg c]  }
|
|k\  r|
n|
t         j                  z    }}
|j                          ||d   f|d   |fgS ||fgS c c}
w )aa  Returns the visible parts of an arc intersecting with a construction box
    as (start angle, end angle) tuples.

    Args:
        center: center of the arc
        radius: radius of the arc
        start_angle: start angle of arc in radians
        end_angle: end angle of arc in radians
        box: construction box which may intersect the arc

    r   rb   r   rU   )r  taur   r  border_linesintersect_liner*   appendrr  r   sort)r'   r  r  r  boxintersection_anglesarclineintersection_pointr*   r  s              r.   r  r    s[   & (*488KI
[14<<	3JC   " 2"%"4"4T": 	2'&077$((BE&#**51\\"5b"95A#**51	22 1$"CV#>?a;&AL8# # 	  "-a01 #Y/
 	
 i())#s   >!Ec                    | J d       | j                   j                  j                  }	  ||      }t        d|      S # t        j                  $ r  |d      }Y )w xY w)Nr   r   r   )r  r  rh   r   DXFTableEntryErrorr   )r  r  	get_styler  s       r.   r  r  1  se    ?999?

!!%%I&$ U## ## &*%&s   ? AAc                l    |j                   j                  dd      }|dk(  r| j                  dd      }|S )z:Unscaled character height defined by text style or DIMTXT.r)   r!   dimtxtr   )r  rh   )rz   r<  r)   s      r.   r  r  ;  s4    NN&&x5F}x-Mr/   c                X    | j                   }|j                  r|j                  |      }|S r8   )rO   r   r   )r   r   rO   s      r.   r   r   C  s)    D
{{  &Kr/   )r   zOptional[Vec2]r   )Nrb   r   rE   )r@   r0   rJ   zOptional[float]rK   r   rL   r   rM   rF   r   rF   )rO   rF   rW   rF   r   rF   )r  r
   r  r
   r  r
   r   r  )r
  r
   r{  r    r  r0   r   r  )r  r   r  rF   r   r
   )r'   r
   r  r0   r  r0   r  r0   r  r   r   zlist[tuple[float, float]])r  z	'Drawing'r  rF   r   r   )rz   r   r<  r   r   r0   )r   r   r   rZ   r   rF   )C
__future__r   typingr   r   r   r   r   r  ra  
ezdxf.mathr	   r
   r   r   r   r   r   r   r   r   ezdxf.lldxfr   ezdxf.enumsr   ezdxf._optionsr   ezdxf.lldxf.constr   r   ezdxf.toolsr   ezdxf.render.arrowsr   ezdxf.entitiesr   r   ezdxf.documentr   r   ezdxf.eztypesr   r    r   _TOLERANCE_COMMONr   r   r   r:   rA   rR   rX   rZ   r   r   r   r   rd  rh  r  r  r  r  r  r  r  r   r?   r/   r.   <module>r7     s   #   
  : 9  + " C & & 6&(/Qo Q 
5 '*4 '*>> 5 #  	
  	6DcP cPL* *Z$ $N% %>q qh	 4W, W,tjC jCZ	;;");7<;;,0/*/*/* /* 	/*
 
/* /*d$r/   