
    'jIx                    v   d dl mZ d dlmZmZmZmZ d dlZd dlm	Z	 d dl
mZ d dlmZmZ d dlZer6d dlmZ d dlmZmZmZmZmZmZmZmZmZmZmZmZ d d	lmZm Z  d d
l!m"Z" d dl#m$Z$ g dZ%d:d;dZ&	 	 d<d=dZ'	 	 d>d?d Z(	 d@dAd!Z) G d" d          Z*h d#Z+dBd&Z,dCdDd,Z-dCdEd/Z.dFd4Z/dCdGd7Z0 G d8 d9          Z1dS )H    )annotations)TYPE_CHECKINGIterableMappingOptionalN)
TABLENAMES)Tags)BoundaryPathTypeEdgeType)DXFTag)InsertMText
LWPolylinePolylineSplineLeader	DimensionImageMeshHatchMPolygonWipeout)	DXFEntityLinetype)
DXFPolygon)BlockLayout)entities_to_codeblock_to_codetable_entries_to_codeblackX   Tcodestrfastboolreturnc                p    ddl }|                                }||_        |                    | ||          S )a  Returns the source `code` as a single string formatted by `Black`_

    Requires the installed `Black`_ formatter::

        pip3 install black

    Args:
        code: source code
        line_length: max. source code line length
        fast: ``True`` for fast mode, ``False`` to check that the reformatted
            code is valid

    Raises:
        ImportError: Black is not available

    .. _black: https://pypi.org/project/black/

    r   N)r$   mode)r    FileModeline_lengthformat_file_contents)r"   r*   r$   r    r(   s        O/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/addons/dxf2code.pyr    r    (   s?    ( LLL>>D"D%%dD%AAA    layoutentitiesIterable[DXFEntity]ignoreOptional[Iterable[str]]Codec                ^    t          |          }|                    | |           |j        S )ar  
    Translates DXF entities into Python source code to recreate this entities
    by ezdxf.

    Args:
        entities: iterable of DXFEntity
        layout: variable name of the layout (model space or block) as string
        ignore: iterable of entities types to ignore as strings
            like ``['IMAGE', 'DIMENSION']``

    Returns:
        :class:`Code`

    r.   r1   _SourceCodeGeneratortranslate_entitiesr"   )r/   r.   r1   r"   s       r,   r   r   C   s5    &  v...DHV4449r-   docblockr   drawingc                   | j         J t          | j                                                   }|                    d          }|                    d          }t	          d          }d| d| d| d	}|                    |           |                    t          |d
                     |                    d           |                    d           |                    | |           |j	        S )aK  
    Translates a BLOCK into Python source code to recreate the BLOCK by ezdxf.

    Args:
        block: block definition layout
        drawing: variable name of the drawing as string
        ignore: iterable of entities types to ignore as strings
            like ['IMAGE', 'DIMENSION']

    Returns:
        :class:`Code`

    Nname
base_pointbr5   zb = z.blocks.new("z", base_point=z, dxfattribs={   indentz    })r6   )
r;   _purge_handles
dxfattribspopr8   add_source_code_lineadd_source_code_lines_fmt_mappingr9   r"   )r;   r<   r1   rF   
block_namer?   r"   prologs           r,   r   r   [   s    $ ;""" 6 6 8 899J''J--Js+++D_G__*__J___Ff%%%|JqAAABBBg&&&c"""E&1119r-   c                Z    t          |          }|                    |            |j        S )Nr:   r7   )r/   r<   r"   s      r,   r   r   {   s0      G,,,DH%%%9r-   c                  f    e Zd ZdZddZddd	ZdddZddZdddZddZ	dddZ
dddZdddZdS )r3   zSource code container.r&   Nonec                    g | _         t                      | _        t                      | _        t                      | _        t                      | _        t                      | _        t                      | _        d S N)r"   setimportslayersstyles	linetypes	dimstylesblocksselfs    r,   __init__zCode.__init__   sO    !	!$ # ##&55#&55 #r-   r   rC   intr#   c                Z    d|z  d                     fd| j        D                       S )zReturns the source code as a single string.

        Args:
            indent: source code indentation count by spaces

         
c              3  "   K   | ]	}|z   V  
d S rR    .0linelead_strs     r,   	<genexpr>z Code.code_str.<locals>.<genexpr>   s'      ??TD??????r-   )joinr"   r[   rC   rf   s     @r,   code_strzCode.code_str   s7     <yy????TY??????r-   r!   c                F    t          |                                 |          S )zReturns the source code as a single string formatted by `Black`_

        Args:
            line_length: max. source code line length

        Raises:
            ImportError: Black is not available

        )r    rj   )r[   r*   s     r,   black_code_strzCode.black_code_str   s     T]]__k222r-   c                *    |                                  S )z+Returns the source code as a single string.)rj   rZ   s    r,   __str__zCode.__str__   s     }}r-   c                Z    d|z  d                     fd| j        D                       S )zReturns required imports as a single string.

        Args:
            indent: source code indentation count by spaces

        r_   r`   c              3  "   K   | ]	}|z   V  
d S rR   rb   rc   s     r,   rg   z"Code.import_str.<locals>.<genexpr>   s'      BBTDBBBBBBr-   )rh   rT   ri   s     @r,   
import_strzCode.import_str   s7     <yyBBBBT\BBBBBBr-   	statementc                :    | j                             |           dS )zWAdd import statement, identical import statements are merged
        together.
        N)rT   addr[   rr   s     r,   
add_importzCode.add_import   s      	#####r-   r"   c                F    | j                             d|z  |z              dS )z9Add a single source code line without line ending ``\n``.r_   N)r"   appendr[   r"   rC   s      r,   add_linezCode.add_line   s'    	v,-----r-   Iterable[str]c                >    |D ]}|                      ||           dS )z:Add multiple source code lines without line ending ``\n``.rB   N)rz   )r[   r"   rC   re   s       r,   	add_lineszCode.add_lines   s4     	/ 	/DMM$vM....	/ 	/r-   c                   | j                             |j                    | j                            |j                   | j                            |j                   | j                            |j                   | j                            |j                   | j                            |j                   |                     |j        |           dS )z!Add another :class:`Code` object.rB   N)	rT   updaterU   rW   rV   rX   rY   r}   r"   ry   s      r,   mergez
Code.merge   s     	DL)))4;'''dn---4;'''dn---4;''' 	ty00000r-   N)r&   rP   r   )rC   r]   r&   r#   )r!   )r&   r#   rr   r#   r&   rP   )r"   r#   rC   r]   r&   rP   )r"   r{   rC   r]   r&   rP   )r"   r3   rC   r]   r&   rP   )__name__
__module____qualname____doc__r\   rj   rl   rn   rq   rv   rz   r}   r   rb   r-   r,   r3   r3      s          & & & &@ @ @ @ @
3 
3 
3 
3 
3   
C C C C C$ $ $ $. . . . ./ / / / /
1 1 1 1 1 1 1r-   >   ownerhandle
paperspacematerial_handleplotstyle_handlevisualstyle_handleattribsdictc                >    d |                                  D             S )zPurge handles from DXF attributes which will be invalid in a new
    document, or which will be set automatically by adding an entity to a
    layout (paperspace).

    Args:
        attribs: entity DXF attributes dictionary

    c                ,    i | ]\  }}|t           v||S rb   )_PURGE_DXF_ATTRIBUTES)rd   kvs      r,   
<dictcomp>z"_purge_handles.<locals>.<dictcomp>   s)    OOOTQ9N0N0NAq0N0N0Nr-   )items)r   s    r,   rE   rE      s!     POW]]__OOOOr-   mappingr   rC   r]   r{   c              #    K   d|z  dz   }|                                  D ]m\  }}t          |t                    sJ t          |t                    rt          j        |          }nt          |          }|                    ||          V  nd S )Nr_   z	'{}': {},)r   
isinstancer#   jsondumpsformat)r   rC   fmtr   r   s        r,   rJ   rJ      s      
,
$C  1!S!!!!!a 	
1AAAAjjA r-   lr   c              #     K   dd}d|z  dz   }| D ]`}t          |t          t          t          f          st	           ||                    }|                    t          |                    V  ad S )Nvaluesr   r&   c              3  t   K   | D ]2}t          |t          j                  rt          |          V  .|V  3d S rR   )r   npfloat64float)r   values     r,   cleanupz_fmt_list.<locals>.cleanup   sS       	 	E%,, Ell""""		 	r-   r_   z{},)r   r   r&   r   )r   r   r]   r#   tupler   )r   rC   r   r   r   s        r,   	_fmt_listr      s          ,
C ! !!eS#.// 	"ggajj!!AjjQ      ! !r-   	func_callargsrF   	list[str]c                <   t          |          rt                    ng d	fd}| g}|                     |                       |                    d           |                    t	          d                     |                    ddg           |S )
Nr&   r{   c               3     K   D ]m} | vr                     |           }t          |t                    rt          j        |          }nt          |          }d                    | |          V  nd S )N
    {}={},)rG   r   r#   r   r   r   )argr   valuestrr   
attributess      r,   fmt_keywordsz#_fmt_api_call.<locals>.fmt_keywords  s       	5 	5C*$$NN3''E%%% &:e,,u::%%c8444444	5 	5r-       dxfattribs={   rB       },rD   )r&   r{   )r   listextendrx   rJ   )r   r   rF   r   sr   s    `   @r,   _fmt_api_callr     s     j!!J%4:::2D	5 	5 	5 	5 	5 	5 	5 
AHH\\^^HH   HH\*Q///000HH	
   Hr-   tagsIterable[DXFTag]c              #     K   d|z  dz   }| D ]m\  }}t          |t                    sJ t          |t                    rt          j        |          }nt          |          }|                    ||          V  nd S )Nr_   zdxftag({}, {}),)r   r]   r#   r   r   r   )r   rC   r   r"   r   s        r,   _fmt_dxf_tagsr   &  s      
,*
*C & &e$$$$$$eS!! 	Ju%%EEJJEjju%%%%%%& &r-   c                     e Zd ZdZdidjdZdkd
Z	 dldmdZdndZdodZdpdZ	dqdZ
	 	 	 drdsd#Z	 	 	 dtdud'Z	 dvdwd-Z	 dxdyd2Z	 dxdzd5Zd{d6Zdkd7Zdkd8Zdkd9Zdkd:Zdkd;Zdkd<Zdkd=Zdkd>Zdkd?Zdkd@ZdkdAZdkdBZdkdCZd|dEZd}dGZd~dIZ ddKZ!ddMZ"ddOZ#ddQZ$ddSZ%ddUZ&ddWZ'ddYZ(dd[Z)dd]Z*dd_Z+ddbZ,dddZ-ddfZ.ddhZ/dS )r8   al  
    The :class:`_SourceCodeGenerator` translates DXF entities into Python source
    code for creating the same DXF entity in another model space or block
    definition.

    :ivar code: list of source code lines without line endings
    :ivar required_imports: list of import source code lines, which are required
        to create executable Python code.

    r.   r:   r#   c                H    || _         || _        t                      | _        d S rR   )r:   r.   r3   r"   )r[   r.   r:   s      r,   r\   z_SourceCodeGenerator.__init__=  s    FF			r-   entityr   r&   rP   c                    |                                 }	 t          | d|                                z             } ||           dS # t          $ r |                     d| d           Y dS w xY w)zTranslates one DXF entity into Python source code. The generated
        source code is appended to the attribute `source_code`.

        Args:
            entity: DXFEntity object

        _z# unsupported DXF entity ""N)dxftypegetattrlowerAttributeErrorrH   )r[   r   r   entity_translators       r,   translate_entityz%_SourceCodeGenerator.translate_entityB  s     ..""	& 'cGMMOO.C D D f%%%%%  	O 	O 	O%%&M7&M&M&MNNNNNN	Os   %A #A/.A/Nr/   r0   r1   r2   c                    |rt          |          nt                      }|D ]-}|                                |vr|                     |           .dS )a<  Translates multiple DXF entities into Python source code. The
        generated source code is appended to the attribute `source_code`.

        Args:
            entities: iterable of DXFEntity
            ignore: iterable of entities types to ignore as strings
                like ['IMAGE', 'DIMENSION']

        N)rS   r   r   )r[   r/   r1   r   s       r,   r9   z'_SourceCodeGenerator.translate_entitiesR  s_     !'1VCEE 	. 	.F~~v--%%f---	. 	.r-   rF   r   c                R   d|v r%| j         j                            |d                    d|v r%| j         j                            |d                    d|v r%| j         j                            |d                    d|v r'| j         j                            |d                    dS dS )zRegister used resources like layers, line types, text styles and
        dimension styles.

        Args:
            dxfattribs: DXF attributes dictionary

        layerlinetypestyledimstyleN)r"   rU   rt   rW   rV   rX   )r[   rF   s     r,   add_used_resourcesz'_SourceCodeGenerator.add_used_resourcesf  s     j  I  G!4555##I##Jz$:;;;j  I  G!4555##I##Jz$:;;;;; $#r-   rr   c                :    | j                             |           d S rR   )r"   rv   ru   s     r,   add_import_statementz)_SourceCodeGenerator.add_import_statementw  s    	Y'''''r-   r"   c                :    | j                             |           d S rR   )r"   rz   r[   r"   s     r,   rH   z)_SourceCodeGenerator.add_source_code_linez  s    	4     r-   r{   c                h    t          |t                    rJ | j                            |           d S rR   )r   r#   r"   r}   r   s     r,   rI   z*_SourceCodeGenerator.add_source_code_lines}  s4    dC(((((	D!!!!!r-   []r   r   r   rL   epilogrC   r]   c                   d|z  dz   }|                      |                    |                     |                     t          |d|z                        |                      |                    |                     d S Nr_   z{}rA   rB   )rH   r   rI   r   )r[   r   rL   r   rC   fmt_strs         r,   add_list_source_codez)_SourceCodeGenerator.add_list_source_code  s}     ,%!!'.."8"8999""9VAJ#G#G#GHHH!!'.."8"899999r-   {}r   c                   d|z  dz   }|                      |                    |                     |                     t          |d|z                        |                      |                    |                     d S r   )rH   r   rI   rJ   )r[   r   rL   r   rC   r   s         r,   add_dict_source_codez)_SourceCodeGenerator.add_dict_source_code  s}     ,%!!'.."8"8999""<F
#K#K#KLLL!!'.."8"899999r-   tags = Tags(rD   rA   r   r	   c                   d|z  dz   }|                      |                    |                     |                     t          |d|z                        |                      |                    |                     d S r   )rH   r   rI   r   )r[   r   rL   r   rC   r   s         r,   add_tags_source_codez)_SourceCodeGenerator.add_tags_source_code  s}     ,%!!'.."8"8999""=a&j#I#I#IJJJ!!'.."8"899999r-   e = r   r   prefixc                    t          |          }|                     |           | | j         dd| ddg}|                    t	          |d                     |                    ddg           |S )	a)  Returns the source code strings to create a DXF entity by a generic
        `new_entity()` call.

        Args:
            dxftype: DXF entity type as string, like 'LINE'
            dxfattribs: DXF attributes dictionary
            prefix: prefix string like variable assignment 'e = '

        z.new_entity(z    '',r   r   rB   r   rD   )rE   r   r.   r   rJ   )r[   r   rF   r   r   s        r,   generic_api_callz%_SourceCodeGenerator.generic_api_call  s     $J//

+++0t{000G

 	
j333444		
 	
 	
 r-   api_callr   c                ^    t          |          }| | j         d| }t          |||          S )aW  Returns the source code strings to create a DXF entity by the
        specialised API call.

        Args:
            api_call: API function call like 'add_line('
            args: DXF attributes to pass as arguments
            dxfattribs: DXF attributes dictionary
            prefix: prefix string like variable assignment 'e = '

        .)rE   r.   r   )r[   r   r   rF   r   r   s         r,   r   z_SourceCodeGenerator.api_call  s=    " $J//
7t{77X77	Yj999r-   c                   | j          dt          |          }t          |          }|                    d          }d| d| dd| dd| d	d
g}|                    t          |d                     |                    ddg           |S )zReturns the source code strings to create a new table entity by
        ezdxf.

        Args:
            dxftype: table entry type as string, like 'LAYER'
            dxfattribs: DXF attributes dictionary

        r   r>   zif 'z	' not in :z    t = z.new(z	        'r   z        dxfattribs={   rB   z
        },z    ))r:   r   rE   rG   r   rJ   )r[   r   rF   tabler>   r   s         r,   new_table_entryz$_SourceCodeGenerator.new_table_entry  s     833j133#J//
~~f%%*4**%***#u###    "	
 	
j444555		
 	
 	
 r-   c                    |                      |                     dddg|                                                     d S )Nz	add_line(startendrI   r   rF   r[   r   s     r,   _linez_SourceCodeGenerator._line  sH    ""MM+'79J9J9L9LMM	
 	
 	
 	
 	
r-   c                    |                      |                     ddg|                                                     d S )Nz
add_point(locationr   r   s     r,   _pointz_SourceCodeGenerator._point  sE    ""MM,f6G6G6I6IJJ	
 	
 	
 	
 	
r-   c                    |                      |                     dddg|                                                     d S )Nzadd_circle(centerradiusr   r   s     r,   _circlez_SourceCodeGenerator._circle  sM    ""MM(3V5F5F5H5H 	
 	
 	
 	
 	
r-   c                    |                      |                     dg d|                                                     d S )Nzadd_arc()r   r   start_angle	end_angler   r   s     r,   _arcz_SourceCodeGenerator._arc   sP    ""MM@@@!!## 	
 	
 	
 	
 	
r-   c                    |                      |                     ddg|                                                     d S )Nz	add_text(textr   r   s     r,   _textz_SourceCodeGenerator._text	  sE    ""MM+x1B1B1D1DEE	
 	
 	
 	
 	
r-   c                |    |                      |                     d|                                                     d S )NSOLIDrI   r   rF   r   s     r,   _solidz_SourceCodeGenerator._solid  C    ""!!'6+<+<+>+>??	
 	
 	
 	
 	
r-   c                |    |                      |                     d|                                                     d S )NTRACEr  r   s     r,   _tracez_SourceCodeGenerator._trace  r  r-   c                |    |                      |                     d|                                                     d S )N3DFACEr  r   s     r,   _3dfacez_SourceCodeGenerator._3dface  C    ""!!(F,=,=,?,?@@	
 	
 	
 	
 	
r-   c                    |                      |                     dg d|                                                     d S )Nz
add_shape()r>   insertsizer   r   s     r,   _shapez_SourceCodeGenerator._shape  sO    ""MM888&:K:K:M:M 	
 	
 	
 	
 	
r-   c                    |                      |                     dg d|                                                     d S )Nzadd_attrib()tagr  r  r   r   s     r,   _attribz_SourceCodeGenerator._attrib$  sO    ""MM888&:K:K:M:M 	
 	
 	
 	
 	
r-   c                |    |                      |                     d|                                                     d S )NATTDEFr  r   s     r,   _attdefz_SourceCodeGenerator._attdef+  r  r-   c                    |                      |                     dg d|                                                     d S )Nzadd_ellipse()r   
major_axisratiostart_param	end_paramr   r   s     r,   _ellipsez_SourceCodeGenerator._ellipse0  sP    ""MMMMM!!## 	
 	
 	
 	
 	
r-   c                    |                      |                     d|                                                     |                     d           d S )NVIEWPORTzm# Set valid handles or remove attributes ending with "_handle", otherwise the DXF file is invalid for AutoCAD)rI   r   rF   rH   r   s     r,   	_viewportz_SourceCodeGenerator._viewport9  sb    ""!!*f.?.?.A.ABB	
 	
 	
 	!!<	
 	
 	
 	
 	
r-   r   c                   | j         j                            |j        j                   |                     |                     dddg|                                                     t          |j	                  r|j	        D ]y}|                                }|j        j
        |d<   |                     |                     d|                                d                     |                     d           xd S d S )	Nzadd_blockref(r>   r  r   ATTRIBza = )r   ze.attribs.append(a))r"   rY   rt   dxfr>   rI   r   rF   lenr   r   r   rH   )r[   r   attribrF   s       r,   _insertz_SourceCodeGenerator._insertD  s'   	VZ_---""MM&(!3V5F5F5H5H 	
 	
 	

 v~ 	A . 
A 
A#..00
 J$  **)) &"3"3"5"5f *    
 ))*?@@@@	A 	A
A 
Ar-   r   c                    |                      |                     d|                                                     |                     d                    t          j        |j                                       d S )NMTEXTze.text = {})rI   r   rF   rH   r   r   r   r  r   s     r,   _mtextz_SourceCodeGenerator._mtextX  so    ""!!'6+<+<+>+>??	
 	
 	

 	!!-"6"6tz&+7N7N"O"OPPPPPr-   r   c                    |                      |                     d|                                                     |                     |                                dd           d S )N
LWPOLYLINEze.set_points([])rL   r   )rI   r   rF   r   
get_pointsr   s     r,   _lwpolylinez _SourceCodeGenerator._lwpolyline`  sv    ""!!,0A0A0C0CDD	
 	
 	
 	!!(8 	" 	
 	
 	
 	
 	
r-   r   c                   |                      |                     ddg|                                                     t          |j                  r|                     |j        dd           t          |j                  r|                     |j        dd           t          |j                  r|                     |j        dd           t          |j                  r|                     |j        dd           d S d S )	Nzadd_spline(degreeze.fit_points = [r   r/  ze.control_points = [ze.knots = [ze.weights = [)	rI   r   rF   r&  
fit_pointsr   control_pointsknotsweightsr   s     r,   _splinez_SourceCodeGenerator._splinei  s=   ""MM-(V5F5F5H5HII	
 	
 	
 v !! 	%%!*<S &    v$%% 	%%%.DS &    v| 	%%]3 &    v~ 	%%s &     	 	r-   r   c                \   |                      |                     d|                                                     |j        D ]h}t	          |                                          }|                    d          }d|v r|d= |                     dt          |           d| d           id S )NPOLYLINEr   r   ze.append_vertex(z, dxfattribs=rD   )rI   r   rF   verticesrE   rG   rH   r#   )r[   r   r   r   r   s        r,   	_polylinez_SourceCodeGenerator._polyline  s    ""!!*f.?.?.A.ABB	
 	
 	
  	 	A$Q\\^^44G{{:..H'!!
 %%I3x==IIwIII   	 	r-   r   c                    |                      d           |                     |                     d|                                                     |                     |j        dd           d S )N8# Dimension style attribute overriding is not supported!LEADERze.set_vertices([r.  r/  )rH   rI   r   rF   r   r;  r   s     r,   _leaderz_SourceCodeGenerator._leader  s    !!F	
 	
 	
 	""!!(F,=,=,?,?@@	
 	
 	
 	!!O$6t 	" 	
 	
 	
 	
 	
r-   r   c                    |                      d           |                     d           |                     |                     d|                                                     |                     g d           d S )Nz3from ezdxf.dimstyleoverride import DimStyleOverrider>  	DIMENSION)z?# You have to create the required graphical representation for zA# the DIMENSION entity as anonymous block, otherwise the DXF filez0# is invalid for AutoCAD (but not for BricsCAD):z# DimStyleOverride(e).render() )r   rH   rI   r   rF   r   s     r,   
_dimensionz_SourceCodeGenerator._dimension  s    !!A	
 	
 	
 	!!F	
 	
 	
 	""!!+v/@/@/B/BCC	
 	
 	
 	""  	
 	
 	
 	
 	
r-   r   c                F   |                      d           |                     |                     d|                                                     t	          |j                  r'|                     d |j        D             dd           |                      d           d S )NzM# Image requires IMAGEDEF and IMAGEDEFREACTOR objects in the OBJECTS section!IMAGEc              3     K   | ]}|V  d S rR   rb   rd   r   s     r,   rg   z._SourceCodeGenerator._image.<locals>.<genexpr>  "      11q111111r-   e.set_boundary_path([r.  r/  zh# Set valid image_def_handle and image_def_reactor_handle, otherwise the DXF file is invalid for AutoCAD)rH   rI   r   rF   r&  boundary_pathr   r   s     r,   _imagez_SourceCodeGenerator._image  s    !!	
 	
 	
 	""!!'6+<+<+>+>??	
 	
 	
 v#$$ 	%%11F0111. &   
 	!!<	
 	
 	
 	
 	
r-   r   c                    |                      |                     d|                                                     t          |j                  r)|                     d |j        D             dd           d S d S )NWIPEOUTc              3     K   | ]}|V  d S rR   rb   rH  s     r,   rg   z0_SourceCodeGenerator._wipeout.<locals>.<genexpr>  rI  r-   rJ  r.  r/  )rI   r   rF   r&  rK  r   r   s     r,   _wipeoutz_SourceCodeGenerator._wipeout  s    ""!!)V->->-@-@AA	
 	
 	
 v#$$ 	%%11F0111. &     	 	r-   r   c                2   |                      |                     dg |                                                     t          |j                  r|                     |j        dd           t          |j                  r'|                     d |j        D             dd           t          |j                  r'|                     d |j        D             dd           t          |j                  r|                     |j        d	d           d S d S )
Nz	add_mesh(ze.vertices = [r   r/  c              3  4   K   | ]}t          |          V  d S rR   r   )rd   es     r,   rg   z-_SourceCodeGenerator._mesh.<locals>.<genexpr>  (      00aq000000r-   ze.edges = [c              3  4   K   | ]}t          |          V  d S rR   rS  )rd   fs     r,   rg   z-_SourceCodeGenerator._mesh.<locals>.<genexpr>  rU  r-   ze.faces = [ze.creases = [)	rI   r   rF   r&  r;  r   edgesfacescreasesr   s     r,   _meshz_SourceCodeGenerator._mesh  sV   ""MM+r6+<+<+>+>??	
 	
 	
 v 	%%(8 &    v| 	%%006<000$ &   
 v| 	%%006<000$ &   
 v~ 	%%s &     	 	r-   r   c                    |                                 }d|d<   |                     |                     ddg|                     |                     |           d S )Nr   associativez
add_hatch(color)rF   rI   r   _polygonr[   r   rF   s      r,   _hatchz_SourceCodeGenerator._hatch  sd    &&((
$%
=!""MM,	:>>	
 	
 	
 	fr-   r   c                   |                                 }|                     |                     ddg|                     |j        j        r#|                     d|j        j         d           |                     |           d S )Nzadd_mpolygon(r^  ze.set_solid_fill(color=z)
)rF   rI   r   r%  
solid_fillrH   
fill_colorr_  r`  s      r,   	_mpolygonz_SourceCodeGenerator._mpolygon  s    &&((
""MM/G9jAA	
 	
 	
 :  	%%D&**?DDD   	fr-   r   c                   | j         }t          |j                  r |d|j         d           |j        rJ|                     t          t          |j        j                  dd           |                      d           d}|j        !|j        } |d            ||	                    d	t          |j
                                        ||	                    d
t          |j                                        ||	                    d|j                              ||	                    d|j                              ||	                    d|j                              ||	                    dt          j        |j                                        |d           t%          |j        d          D ]\  }}|j        t*          j        k    r |d	                    |                     |                     |j        dd            ||	                    dt          |j                                        ||	                    dt          |j                                        |d            |d| d            |d|j         d           |j        D ](}|j        t6          j        k    r* |d|j         dt          |j                   d           B|j        t6          j        k    r |d            ||	                    dt          |j                                         ||	                    d|j!                              ||	                    d|j"                              ||	                    d|j#                              ||	                    d |j$                              |d           0|j        t6          j%        k    r
 |d!            ||	                    dt          |j                                         ||	                    d"t          |j&                                        ||	                    d#|j'                              ||	                    d|j"                              ||	                    d|j#                              ||	                    d |j$                              |d           P|j        t6          j(        k    r |d$           |j)        r; ||	                    d%t          d& |j)        D                                            |j*        r; ||	                    d't          d( |j*        D                                            |j+        r1 ||	                    d)t          |j+                                       |j,        r1 ||	                    d*t          |j,                                        ||	                    d+|j-                              ||	                    d,|j.                             |j/        1 ||	                    d-t          |j/                                       |j0        1 ||	                    d.t          |j0                                        |d           *d S )/Nze.set_seed_points(rD   ze.set_pattern_definition([r.  r/  ze.dxf.solid_fill = 0r   ze.set_gradient(color1color2rotationcentered	one_colorr>      )r   z# {}. polyline pathze.paths.add_polyline_path([z    ],	is_closedflagsz# z,. edge path: associative hatch not supportedz!ep = e.paths.add_edge_path(flags=zep.add_line(z, zep.add_arc(r   r   r   r   ccwzep.add_ellipse(r  r  zep.add_spline(r4  c                    g | ]}|S rb   rb   )rd   fps     r,   
<listcomp>z1_SourceCodeGenerator._polygon.<locals>.<listcomp>F  s    (F(F(F(F(F(Fr-   r5  c                    g | ]}|S rb   rb   )rd   cps     r,   rr  z1_SourceCodeGenerator._polygon.<locals>.<listcomp>M  s    (J(J(J(J(J(Jr-   knot_valuesr7  r3  periodicstart_tangentend_tangent)1rH   r&  seedspatternr   mapr#   linesgradientr   rg  rh  ri  rj  rk  r   r   r>   	enumeratepathstyper
   r:  r;  rm  path_type_flagsrX  r   LINEr   r   ARCr   r   r   r   ro  ELLIPSEr  r  SPLINEr4  r5  ru  r7  r3  rv  rw  rx  )r[   r   rz   r   gcountpathedges           r,   r_  z_SourceCodeGenerator._polygon  s   ,v| 	;H9&,999:::> 	>%%C-..3 &   
 %%&<===?&AH&'''HSZZ#ah--88999HSZZ#ah--88999HSZZ
AJ77888HSZZ
AJ77888HSZZQ[99:::HSZZ
16(:(:;;<<<HSMMM$V\;;; L	& L	&KE4y,555.55e<<===))M8# *   
 KT^1D1DEEFFFGS1E-F-FGGHHHLLLL   O8LOOO   !J :& :&DyHM11 !N
!N!Nc$(mm!N!N!NOOOOhl22 !/// Hc$+6F6F!G!GHHH Hdk!B!BCCC M4;K!L!LMMM K!H!HIII E48!<!<=== h&666 !!2333 Hc$+6F6F!G!GHHH L#do:N:N!O!OPPP GTZ!@!@AAA M4;K!L!LMMM K!H!HIII E48!<!<=== ho55 !1222? $H #

$0$'(F(Fdo(F(F(F$G$G!" !"    . $H #

$4$'(J(Jd6I(J(J(J$K$K!" !"    + $H #

=#d>N:O:O P P    < O$HSZZ	3t|;L;L%M%MNNN Hdk!B!BCCC J!F!FGGG-9$H #

$3S9K5L5L!" !"  
  +7$H #

=#d>N:O:O P P   !u:&%L	& L	&r-   r   c                |    |                      |                     d|                                                     d S )NLAYERrI   r   rF   )r[   r   s     r,   _layerz_SourceCodeGenerator._layere  C    ""  %*:*:*<*<==	
 	
 	
 	
 	
r-   ltyper   c                j   |                      d           |                      d           |                      d           |                     |                     d|                                                     |                     |j        j        ddd           |                     d	           d S )
Nz!from ezdxf.lldxf.tags import Tagsz$from ezdxf.lldxf.types import dxftagz0from ezdxf.entities.ltype import LinetypePatternLTYPEztags = Tags([r.  rA   )rL   r   rC   z*    t.pattern_tags = LinetypePattern(tags))r   rI   r   rF   r   pattern_tagsr   rH   )r[   r  s     r,   _ltypez_SourceCodeGenerator._ltypej  s    !!"EFFF!!"HIII!!>	
 	
 	
 	""  %*:*:*<*<==	
 	
 	
 	!!#"	 	" 	
 	
 	
 	!!"NOOOOOr-   r   c                |    |                      |                     d|                                                     d S )NSTYLEr  )r[   r   s     r,   _stylez_SourceCodeGenerator._style{  r  r-   r   c                |    |                      |                     d|                                                     d S )NDIMSTYLEr  )r[   r   s     r,   	_dimstylez_SourceCodeGenerator._dimstyle  sC    ""  X-@-@-B-BCC	
 	
 	
 	
 	
r-   appidc                |    |                      |                     d|                                                     d S )NAPPIDr  )r[   r  s     r,   _appidz_SourceCodeGenerator._appid  r  r-   )r.   r:   )r.   r#   r:   r#   )r   r   r&   rP   rR   )r/   r0   r1   r2   r&   rP   )rF   r   r&   rP   r   )r"   r#   r&   rP   )r"   r{   r&   rP   )r   r   r   )
r   r   rL   r#   r   r#   rC   r]   r&   rP   )r   r   r   )
r   r   rL   r#   r   r#   rC   r]   r&   rP   )r   rD   rA   )r   r	   )r   )r   r#   rF   r   r   r#   r&   r{   )
r   r#   r   r{   rF   r   r   r#   r&   r{   )r   r#   rF   r   r&   r{   )r   r   r&   rP   )r   r   r&   rP   )r   r   r&   rP   )r   r   r&   rP   )r   r   r&   rP   )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   )0r   r   r   r   r\   r   r9   r   r   rH   rI   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r"  r(  r+  r1  r8  r<  r@  rD  rL  rP  r[  ra  re  r_  r  r  r  r  r  rb   r-   r,   r8   r8   1  s       	 	    
& & & && +/. . . . .(< < < <"( ( ( (! ! ! !" " " " 
: 
: 
: 
: 
: 
: 
: 
: 
: 
: EF: : : : : =C    B : : : : :*   :
 
 
 


 
 
 


 
 
 

 
 
 

 
 
 


 
 
 


 
 
 


 
 
 


 
 
 

 
 
 

 
 
 


 
 
 

 
 
 
A A A A(Q Q Q Q
 
 
 
   2   $	
 	
 	
 	

 
 
 
(
 
 
 
&	 	 	 	   6   	 	 	 	c& c& c& c&L
 
 
 

P P P P"
 
 
 


 
 
 


 
 
 
 
 
r-   r8   )r!   T)r"   r#   r$   r%   r&   r#   )r.   N)r/   r0   r.   r#   r1   r2   r&   r3   )r:   N)r;   r   r<   r#   r1   r2   r&   r3   rN   )r/   r0   r&   r3   )r   r   r&   r   r   )r   r   rC   r]   r&   r{   )r   r   rC   r]   r&   r{   )r   r#   r   r{   rF   r   r&   r   )r   r   rC   r]   )2
__future__r   typingr   r   r   r   r   ezdxf.sections.tablesr   ezdxf.lldxf.tagsr	   ezdxf.entitiesr
   r   numpyr   ezdxf.lldxf.typesr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   ezdxf.entities.polygonr   ezdxf.layoutsr   __all__r    r   r   r   r3   r   rE   rJ   r   r   r   r8   rb   r-   r,   <module>r     s   # " " " " " = = = = = = = = = = = =  , , , , , , ! ! ! ! ! ! 5 5 5 5 5 5 5 5     *((((((                            32222222111111))))))  B B B B B: &*    4 &*    B ,1    Q1 Q1 Q1 Q1 Q1 Q1 Q1 Q1h   	P 	P 	P 	P	 	 	 	 	! ! ! ! !   <& & & & &W	
 W	
 W	
 W	
 W	
 W	
 W	
 W	
 W	
 W	
r-   