
    h02                       S SK Jr  S SKJrJrJr  S SKrS SKrS SKJ	r	  S SK
J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  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!  S SK"J#r#J$r$  S SK%J&r&  S SK%J'r'  S SK(J)r)J*r*  S SK+J,r,  SSK-J.r.  \R^                  " S5      r0Sr1\Rd                  \Rd                  \Rd                  4r3Sr4S S jr5 " S S\5      r6S!S jr7S"S jr8SSSSSSSS.                   S#S jjr9g)$    )annotations)IterableOptionalUnionN)PathLike)LineCollection)	AxesImage)Line2D)	PathPatch)Path)Affine2D)to_matplotlib_path)BackendBkPath2d
BkPoints2d	ImageData)BackendPropertiesLayoutProperties)
FilterFunc)Color)Vec2Matrix44)Layout   )Configurationezdxfgr;p@g?c                   U R                   R                  S5        U R                  R                  S5        U R                  R	                  5        H  nUR                  S5        M     U R                  S5        U R                  SS5        g )NFequaldatalim)xaxisset_visibleyaxisspinesvalues	autoscale
set_aspect)axss     Q/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/drawing/matplotlib.py
setup_axesr*   *   se    HHHHYY	e   LLMM'9%    c                     ^  \ rS rSrSrSS.   SU 4S jjjrSU 4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 jr      SS jrS rU 4S jrSrU =r$ ) MatplotlibBackend5   a  Backend which uses the :mod:`Matplotlib` package for image export.

Args:
    ax: drawing canvas as :class:`matplotlib.pyplot.Axes` object
    adjust_figure: automatically adjust the size of the parent
        :class:`matplotlib.pyplot.Figure` to display all content
T)adjust_figurec               ^   > [         TU ]  5         [        U5        Xl        X l        SU l        g )Nr   )super__init__r*   r'   _adjust_figure
_current_z)selfr'   r/   	__class__s      r)   r2   MatplotlibBackend.__init__>   s)     	2+r+   c                   > UR                   c=  U R                  R                  5       nU(       a  UR                  SUR                  -  S9n[
        TU ]  U5        g )Ng      R@)min_lineweight)r9   r'   
get_figurewith_changesdpir1   	configure)r5   configfigurer6   s      r)   r=   MatplotlibBackend.configureJ   sM      (WW'')F,,D6::<M,N&!r+   c                H    U R                   nU =R                   S-  sl         U$ )Nr   )r4   )r5   zs     r)   _get_zMatplotlibBackend._get_zS   s    OO1r+   c                :    U R                   R                  U5        g N)r'   set_facecolor)r5   colors     r)   set_background MatplotlibBackend.set_backgroundX   s    e$r+   c                    UR                   nU R                  R                  UR                  /UR                  /[
        UU R                  5       S9  g)z Draw a real dimensionless point.r(   czorderN)rH   r'   scatterxySCATTER_POINT_SIZErC   )r5   pos
propertiesrH   s       r)   
draw_pointMatplotlibBackend.draw_point[   sC      UUGUUG ;;= 	 	
r+   c                    U R                   R                  c   e[        UR                  U R                   R                  -  U R                   R                  5      $ )z>Set lineweight_scaling=0 to use a constant minimal lineweight.)r>   r9   max
lineweightlineweight_scaling)r5   rT   s     r)   get_lineweight MatplotlibBackend.get_lineweightf   sJ    {{))555!!DKK$B$BBKK&&
 	
r+   c           
     F   UR                  U5      (       a  U R                  X5        gU R                  R                  [	        UR
                  UR
                  4UR                  UR                  4U R                  U5      UR                  U R                  5       S95        g)zUDraws a single solid line, line type rendering is done by the
frontend since v0.18.1
)	linewidthrH   rN   N)
iscloserU   r'   add_liner
   rP   rQ   r[   rH   rC   )r5   startendrT   s       r)   	draw_lineMatplotlibBackend.draw_linen   sy     ==OOE.GGWWcee$WWcee$"11*=$**;;=r+   c           
     $   UR                   nU R                  U5      n/ n/ n/ nU R                  5       nU H  u  pU	R                  U
5      (       a8  UR	                  U	R
                  5        UR	                  U	R                  5        MS  UR	                  U	R
                  U	R                  4U
R
                  U
R                  445        M     U R                  R                  Xg[        X8S9  U R                  R                  [        UUUUSS95        g)zDFast method to draw a bunch of solid lines with the same properties.rL   butt)
linewidthsrH   rN   capstyleN)rH   r[   rC   r_   appendrP   rQ   r'   rO   rR   add_collectionr   )r5   linesrT   rH   rY   _linespoint_xpoint_yrB   r(   es              r)   draw_solid_lines"MatplotlibBackend.draw_solid_lines   s       ((4
KKMDAyy||qss#qss#QSSzACC:67  	,>%R%	
r+   c                ,   [        U/5      n [        UU R                  U5      SUR                  U R	                  5       S9nU R
                  R                  U5        g! [         a+  n[        R                  S[        U5       35         SnAgSnAff = f)zRDraw a solid line path, line type rendering is done by the
frontend since v0.18.1
F)r^   fillrH   rN   zignored matplotlib error: N)r   r   r[   rH   rC   r'   	add_patch
ValueErrorloggerinfostr)r5   pathrT   mpl_pathpatchro   s         r)   	draw_pathMatplotlibBackend.draw_path   s    
 &tf-	%--j9 &&{{}E GGe$  	?KK4SVH=>>	?s   4A 
B(!BBc                
   Sn [        [        USS9UR                  USU R                  5       S9nU R                  R                  U5        g ! [         a+  n[        R                  S[        U5       35         S nAg S nAff = f)Nr   T)detect_holes)rH   r^   rs   rN   z1ignored matplotlib error in draw_filled_paths(): )
r   r   rH   rC   r'   rt   ru   rv   rw   rx   )r5   pathsrT   r^   r{   ro   s         r)   draw_filled_paths#MatplotlibBackend.draw_filled_paths   s~     		%"5t< &&#{{}E GGe$  	VKKKCPQF8TUU	Vs   -A 
B!A==Bc                    U R                   R                  " [        S UR                  5        5       6 UR                  SU R                  5       S.6  g )Nc              3  P   #    U  H  oR                   UR                  4v   M     g 7frF   )rP   rQ   ).0ps     r)   	<genexpr>8MatplotlibBackend.draw_filled_polygon.<locals>.<genexpr>   s     9'8!CC:'8s   $&r   )rH   r^   rN   )r'   rs   zipverticesrH   rC   )r5   pointsrT   s      r)   draw_filled_polygon%MatplotlibBackend.draw_filled_polygon   s<    9v'89:"";;=		
r+   c                   UR                   R                  u  p4nUS:X  d   e[        U R                  SS9nUR	                  [
        R                  " UR                   SS95        UR                  U R                  5       5        UR                  u  nnn	n
nnnnnnnnnnnn[        [
        R                  " X{U/XU// SQ/5      S9nUR                  UU R                  R                  -   5        U R                  R                  U5        g )N   antialiased)interpolationr   )axis)r   r   r   )matrix)imageshaper	   r'   set_datanpflip
set_zorderrC   	transformr   arrayset_transform	transData	add_image)r5   
image_datarT   heightwidthdepthhandlem11m12m13m14m21m22m23m24m31m32m33m34m41m42m43m44matplotlib_transforms                           r)   
draw_imageMatplotlibBackend.draw_image   s     *//55uzz 477-@
 0 0q9:$++-(&   #	
'88sOsO 
 	1DGG4E4EEF&!r+   c                8    U R                   R                  5         g rF   )r'   clear)r5   s    r)   r   MatplotlibBackend.clear   s    r+   c                  > [         T	U ]  5         U R                  R                  S5        U R                  (       a  U R                  R                  5       u  pU R                  R                  5       u  p4X!-
  XC-
  pe[        R                  " US5      (       dC  [        R                  " Xe-  5      u  pxU R                  R                  5       R                  XxSS9  g g g )NTr   )forward)r1   finalizer'   r%   r3   get_xlimget_ylimmathr_   plt	figaspectr:   set_size_inches)
r5   minxmaxxminymaxy
data_widthdata_heightr   r   r6   s
            r)   r   MatplotlibBackend.finalize   s    $))+JD))+JD&*k4;<<
A.. #k.F G""$44UD4Q /	 r+   )r3   r4   r'   )r'   plt.Axesr/   bool)r>   r   returnNone)r   int)rH   r   )rS   r   rT   r   )rT   r   r   float)ra   r   rb   r   rT   r   )rk   zIterable[tuple[Vec2, Vec2]]rT   r   )ry   r   rT   r   )r   zIterable[BkPath2d]rT   r   )r   r   rT   r   )r   r   rT   r   r   r   )__name__
__module____qualname____firstlineno____doc__r2   r=   rC   rI   rU   r[   rc   rp   r|   r   r   r   r   r   __static_attributes____classcell__)r6   s   @r)   r-   r-   5   s     #	

 	
 
"
%	

$
*
 &
<%&%'%5F%$
+"#+"1B+"	+"Z	R 	Rr+   r-   c                    U R                  5       u  pU R                  5       u  p4X!-
  XC-
  pe[        U5      S:  a  XV-  $ g)Ng&.>g      ?)r   r   abs)r'   r   r   r   r   r   r   s          r)   _get_aspect_ratior     s@    JDJD"k4;
;$''r+   c                d    US:X  a  US:X  a  [        S5      eUS:X  a  X -  nX4$ US:X  a  X-  nX4$ )Ng        zinvalid (width, height) values)ru   )ratior   r   s      r)   _get_width_heightr     sK    |#9::| = 
3=r+   i,  agg)bgfgr<   backendr>   filter_funcsize_inchesc                  SSK Jn	  SSKJn
  SSKnUR                  5       nUR                  U5        Uc
  [        5       n [        R                  " US9nUR                  S5      nU	" U R                  5      n[        R                  " U 5      nUb  UR                  X#5        [        U5      nU
" UUU5      R!                  U SUUS	9  Ub4  [#        U5      n[%        UUS   US   5      u  nnUR'                  UUS5        UR)                  XUR+                  5       SS
9  [        R,                  " U5        UR                  U5        g! UR                  U5        f = f)a  Quick and simplified render export by matplotlib.

Args:
    layout: modelspace or paperspace layout to export
    filename: export filename, file extension determines the format e.g.
        "image.png" to save in PNG format.
    bg: override default background color in hex format #RRGGBB or #RRGGBBAA,
        e.g. use bg="#FFFFFF00" to get a transparent background and a black
        foreground color (ACI=7), because a white background #FFFFFF gets a
        black foreground color or vice versa bg="#00000000" for a transparent
        (black) background and a white foreground color.
    fg: override default foreground color in hex format #RRGGBB or #RRGGBBAA,
        requires also `bg` argument. There is no explicit foreground color
        in DXF defined (also not a background color), but the ACI color 7
        has already a variable color value, black on a light background and
        white on a dark background, this argument overrides this (ACI=7)
        default color value.
    dpi: image resolution (dots per inches).
    size_inches: paper size in inch as `(width, height)` tuple, which also
        defines the size in pixels = (`width` * `dpi`) x (`height` * `dpi`).
        If `width` or `height` is 0.0 the value is calculated by the aspect
        ratio of the drawing.
    backend: the matplotlib rendering backend to use (agg, cairo, svg etc)
        (see documentation for `matplotlib.use() <https://matplotlib.org/3.1.1/api/matplotlib_configuration_api.html?highlight=matplotlib%20use#matplotlib.use>`_
        for a complete list of backends)
    config: drawing parameters
    filter_func: filter function which takes a DXFGraphic object as input
        and returns ``True`` if the entity should be drawn or ``False`` if
        the entity should be ignored

r   )RenderContext)Frontendr   N)r<   )r   r   r   r   T)r   r   layout_properties)r<   	facecolortransparent)rT   r   frontendr   
matplotlibget_backenduser   r   r?   add_axesdocr   from_layout
set_colorsr-   draw_layoutr   r   r   savefigget_facecolorclose)layoutfilenamer   r   r<   r   r>   r   r   r   r   r   old_backendfigr'   ctxr   outr   whs                        r)   qsaver     s9   V *" ((*KNN7~$**-||L1FJJ',88@>((0#c6"..#/	 	/ 	
 "%b)E$UKNKNKDAq1d+H1A1A1CQUV		#{#
{#s    C2E E)r'   r   )r'   r   r   r   )r   r   r   r   r   r   r   ztuple[float, float])r   r   r   zUnion[str, PathLike]r   Optional[Color]r   r   r<   r   r   rx   r>   zOptional[Configuration]r   zOptional[FilterFunc]r   zOptional[tuple[float, float]]r   r   ):
__future__r   typingr   r   r   r   loggingosr   matplotlib.pyplotpyplotr   numpyr   matplotlib.collectionsr   matplotlib.imager	   matplotlib.linesr
   matplotlib.patchesr   matplotlib.pathr   matplotlib.transformsr   ezdxf.npshapesr   ezdxf.addons.drawing.backendr   r   r   r   ezdxf.addons.drawing.propertiesr   r   ezdxf.addons.drawing.type_hintsr   r   
ezdxf.mathr   r   ezdxf.layoutsr   r>   r   	getLoggerrv   POINTSCURVE4CURVE4x3rR   r*   r-   r   r   r    r+   r)   <module>r     s(   # , ,      1 & # (   * - Q Q O 6 1 %   !			7	# 
KKdkk2 &OR ORd &*(,15O$O$"O$ 		O$
 	O$ 
O$ O$ $O$ &O$ /O$ 
O$r+   