Ë
    £èhËC  ã                  ó„  — d dl mZ d dlmZmZmZmZmZmZm	Z	 d dl
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mZ d d	lmZ d d
l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% g d¢Z&h d£Z'eee(f   Z) G d„ d«      Z* G d„ d«      Z+ddd„Z,	 	 d	 	 	 	 	 	 	 dd„Z-	 	 d	 	 	 	 	 	 	 dd„Z.	 	 d	 	 	 	 	 	 	 d d„Z/d!d„Z0y)"é    )Úannotations)ÚIterableÚIteratorÚcastÚBinaryIOÚOptionalÚUnionÚAny)ÚStringIO)ÚPath)ÚDXFStructureError)ÚExtendedTagsÚDXFTag)Ú	TagWriter)Útag_compilerÚascii_tags_loader)Údxf_file_info)Ú	fileindex)Ú
DXFGraphicÚ	DXFEntityÚPolylineÚInsert)Úfactory)Úentity_linker)Ú
toencoding)ÚopendxfÚsingle_pass_modelspaceÚ
modelspace>   ÚARCÚRAYÚLINEÚMESHÚTEXTÚHATCHÚHELIXÚIMAGEÚMLINEÚMTEXTÚPOINTÚSHAPEÚSOLIDÚTRACEÚXLINEÚ3DFACEÚATTDEFÚATTRIBÚCIRCLEÚINSERTÚLEADERÚSEQENDÚSPLINEÚVERTEXÚELLIPSEÚMLEADERÚWIPEOUTÚPOLYLINEÚ	DIMENSIONÚ
LWPOLYLINEc                  ó†   — e Zd ZdZddd„Z	 	 	 	 dd„Zed„ «       Zed„ «       Zdd„Z	dd„Z
	 d	 	 	 dd	„Z	 	 	 	 	 	 dd
„Zd„ Zy)ÚIterDXFu4  Iterator for DXF entities stored in the modelspace.

    Args:
        name: filename, has to be a seekable file.
        errors: specify decoding error handler

            - "surrogateescape" to preserve possible binary data (default)
            - "ignore" to use the replacement char U+FFFD "ï¿½" for invalid data
            - "strict" to raise an :class:`UnicodeDecodeError`exception  for invalid data

    Raises:
        DXFStructureError: invalid or incomplete DXF file
        UnicodeDecodeError: if `errors` is "strict" and a decoding error occurs

    c                ó  — | j                  t        |«      «      \  | _        | _        || _        t        |d¬«      | _        d| j                  vrt        d«      ‚| j                  j                  dkD  rd| j                  vrt        d«      ‚y y )NÚrb©ÚmodeÚENTITIESzENTITIES section not found.ÚAC1009ÚOBJECTSzOBJECTS section not found.)	Ú_load_indexÚstrÚ	structureÚsectionsÚerrorsÚopenÚfiler   Úversion)ÚselfÚnamerJ   s      ú4lib/python3.12/site-packages/ezdxf/addons/iterdxf.pyÚ__init__zIterDXF.__init__R   s~   € Ø(,×(8Ñ(8¼¸T»Ó(CÑ%ˆŒ˜œØˆŒÜ" 4¨dÔ3ˆŒ	Ø˜TŸ]™]Ñ*Ü#Ð$AÓBÐBØ�>‰>×!Ñ! HÒ,°À$Ç-Á-Ñ1OÜ#Ð$@ÓAÐAð 2PÐ,ó    c                ó  — t        j                  |«      }t        «       }g }|j                  D ]N  }|j                  dk(  r|j                  |«       Œ$|j                  dk(  sŒ4t        |«      dz
  ||j                  <   ŒP ||_        ||fS )Nr   é   é   )r   ÚloadÚdictÚindexÚcodeÚappendÚlenÚvalue)rN   rO   rH   rI   Ú	new_indexÚes         rP   rF   zIterDXF._load_index[   s{   € ô —N‘N 4Ó(ˆ	Ü#'£6ˆØˆ	Ø—”ˆAØ�v‰v˜Š{Ø× Ñ  Õ#Ø—‘˜1“Ü$'¨	£N°QÑ$6�˜Ÿ™Ò!ð	 !ð $ˆ	ŒØ˜(Ð"Ð"rR   c                ó.   — | j                   j                  S ©N)rH   Úencoding©rN   s    rP   ra   zIterDXF.encodingj   s   € à�~‰~×&Ñ&Ð&rR   c                ó.   — | j                   j                  S r`   )rH   rM   rb   s    rP   Ú
dxfversionzIterDXF.dxfversionn   s   € à�~‰~×%Ñ%Ð%rR   c                ó  — t        || «      }| j                  j                  | j                  d   dz      j                  }| j
                  j                  d«       | j
                  j                  |«      }|j                  |«       |S )a^  Returns a companion object to export parts from the source DXF file
        into another DXF file, the new file will have the same HEADER, CLASSES,
        TABLES, BLOCKS and OBJECTS sections, which guarantees all necessary
        dependencies are present in the new file.

        Args:
            name: filename, no special requirements

        rC   rU   r   )	ÚIterDXFWriterrH   rX   rI   ÚlocationrL   ÚseekÚreadÚ
write_data)rN   rO   Údocrg   Údatas        rP   ÚexportzIterDXF.exportr   sm   € ô ˜D $Ó'ˆð —>‘>×'Ñ'¨¯©°jÑ(AÀAÑ(EÑF×OÑOˆØ�	‰	�‰�qÔØ�y‰y�~‰~˜hÓ'ˆØ�‰�tÔØˆ
rR   c                ó¸  — | j                   d   }	 | j                  j                  dd|«      }| j                  j
                  |   j                  }| j                  j
                  |dz      j                  }||z
  }| j                  j                  |«       | j                  j                  |«      }|j                  |«       y # t        $ r t	        d«      ‚w xY w)NrE   r   ÚENDSECz$ENDSEC of OBJECTS section not found.rU   )rI   rH   ÚgetÚ
ValueErrorr   rX   rg   rL   rh   ri   Úwrite)rN   ÚfÚstart_indexÚ	end_indexÚstart_locationÚend_locationÚcountrl   s           rP   Úcopy_objects_sectionzIterDXF.copy_objects_section…   s¾   € Ø—m‘m IÑ.ˆð	MØŸ™×*Ñ*¨1¨h¸ÓDˆIð Ÿ™×-Ñ-¨kÑ:×CÑCˆØ—~‘~×+Ñ+¨I¸©MÑ:×CÑCˆØ˜~Ñ-ˆØ�	‰	�‰�~Ô&Ø�y‰y�~‰~˜eÓ$ˆØ	�‰��øô ò 	MÜ#Ð&JÓLÐLð	Mús   ‘C ÃCNc              #  óì   K  — t        «       }d}t        |«      }| j                  | j                  d   dz   |«      D ]-  } ||«      rŒ|j                  j
                  dk(  sŒ&|r|–— |}Œ/ |r|–— yy­w)a÷  Returns an iterator for all supported DXF entities in the
        modelspace. These entities are regular :class:`~ezdxf.entities.DXFGraphic`
        objects but without a valid document assigned. It is **not**
        possible to add these entities to other `ezdxf` documents.

        It is only possible to recreate the objects by factory functions base
        on attributes of the source entity.
        For MESH, POLYMESH and POLYFACE it is possible to use the
        :class:`~ezdxf.render.MeshTransformer` class to render (recreate) this
        objects as new entities in another document.

        Args:
            types: DXF types like ``['LINE', '3DFACE']`` which should be
                returned, ``None`` returns all supported types.

        NrC   rU   r   )r   Ú_requested_typesÚload_entitiesrI   ÚdxfÚ
paperspace)rN   ÚtypesÚlinked_entityÚqueuedÚrequested_typesÚentitys         rP   r   zIterDXF.modelspace“   s   è ø€ ô& &›ˆØˆÜ*¨5Ó1ˆØ×(Ñ(Ø�M‰M˜*Ñ%¨Ñ)¨?ö
ˆFñ ! Õ(¨V¯Z©Z×-BÑ-BÀaÓ-Gñ Ø ’LØ‘ð
ñ Ø‹Lð ùs   ‚AA4ÁA4Á"A4c              #  ó  ‡ K  — dˆ fd„}|}‰ j                   j                  |   }‰ j                  j                  |j                  «       |j
                  dk7  r¥|dz  }‰ j                   j                  |   }|j                  |j                  z
  }‰ j                  j                  |«      }|j
                  |v r2t        j                   ||«      «      }	t        j                  |	«      –— |}|j
                  dk7  rŒ¤y y ­w)Nc                ór   •— | j                  ‰j                  ‰j                  ¬«      j                  dd«      S )N©rJ   z
Ú
)Údecodera   rJ   Úreplace)rl   rN   s    €rP   Úto_strz%IterDXF.load_entities.<locals>.to_str¸   s0   ø€ Ø—;‘;˜tŸ}™}°T·[±[�;ÓA×IÑIØ˜óð rR   ro   rU   )rl   ÚbytesÚreturnrG   )rH   rX   rL   rh   rg   r\   ri   r   Ú	from_textr   rV   )
rN   Ústartr‚   rŠ   rX   ÚentryÚ
next_entryÚsizerl   Úxtagss
   `         rP   r|   zIterDXF.load_entitiesµ   sÌ   øè ø€ õ	ð
 ˆØ—‘×$Ñ$ UÑ+ˆØ�	‰	�‰�u—~‘~Ô&Ø�k‰k˜XÒ%Ø�Q‰JˆEØŸ™×-Ñ-¨eÑ4ˆJØ×&Ñ&¨¯©Ñ7ˆDØ—9‘9—>‘> $Ó'ˆDØ�{‰{˜oÑ-Ü$×.Ñ.©v°d«|Ó<�Ü—l‘l 5Ó)Ò)ØˆEð �k‰k˜XÕ%ùs   ƒC9C?Ã=C?c                ó8   — | j                   j                  «        y)zSafe closing source DXF file.N)rL   Úcloserb   s    rP   r”   zIterDXF.closeÊ   s   € à�	‰	�‰ÕrR   ©Úsurrogateescape)rO   ÚFilenamerJ   rG   )rO   rG   rŒ   z.tuple[fileindex.FileStructure, dict[str, int]])rO   r—   rŒ   rf   )rs   r   rŒ   ÚNoner`   )r   úOptional[Iterable[str]]rŒ   úIterable[DXFGraphic])rŽ   Úintr‚   úset[str]rŒ   rš   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rQ   rF   Úpropertyra   rd   rm   ry   r   r|   r”   © rR   rP   r>   r>   A   s‘   „ ñô Bð#Øð#à	7ó#ð ñ'ó ð'ð ñ&ó ð&óó&ð 04ð Ø,ð à	ó ðDØðØ+3ðà	óó*rR   r>   c                  ó*   — e Zd Zdd„Zdd„Zdd„Zd„ Zy)	rf   c                ó¾   — t        |«      | _        t        |d¬«      | _        t	        «       | _        t        | j
                  |j                  «      | _        || _	        y )NÚwbrA   )
rG   rO   rK   rL   r   Útextr   rd   Úentity_writerÚloader)rN   rO   r¨   s      rP   rQ   zIterDXFWriter.__init__Ð   sD   € Ü˜“IˆŒ	Ü" 4¨dÔ3ˆŒ	Ü“JˆŒ	Ü& t§y¡y°&×2CÑ2CÓDˆÔØˆ�rR   c                ó:   — | j                   j                  |«       y r`   )rL   rr   )rN   rl   s     rP   rj   zIterDXFWriter.write_data×   s   € Ø�	‰	�‰˜ÕrR   c                óŒ  — | j                   j                  d«       | j                   j                  «        |j                  j                  €d| j
                  _        |j                  | j
                  «       |j                  «       dk(  rbt        t        |«      }|j                  D ]  }|j                  | j
                  «       Œ |j                  j                  | j
                  «       n€|j                  «       dk(  rmt        t        |«      }|j                  rQ|j                  D ]  }|j                  | j
                  «       Œ |j                  j                  | j
                  «       | j                   j!                  «       j#                  | j$                  j&                  «      }| j(                  j+                  |«       y)a%  Write a DXF entity from the source DXF file to the export file.

        Don't write entities from different documents than the source DXF file,
        dependencies and resources will not match, maybe it will work once, but
        not in a reliable way for different DXF documents.

        r   NFr:   r2   )r¦   rh   Útruncater}   Úhandler§   Úwrite_handlesÚ
export_dxfÚdxftyper   r   ÚverticesÚseqendr   Úattribs_followÚattribsÚgetvalueÚencoder¨   ra   rL   rr   )rN   rƒ   ÚpolylineÚvertexÚinsertÚattribrl   s          rP   rr   zIterDXFWriter.writeÚ   sB  € ð" 	�	‰	�‰�qÔØ�	‰	×ÑÔà�:‰:×ÑÐ$Ø/4ˆD×ÑÔ,à×Ñ˜$×,Ñ,Ô-Ø�>‰>Ó˜zÒ)ÜœH fÓ-ˆHØ"×+Ô+�Ø×!Ñ! $×"4Ñ"4Õ5ð ,à�O‰O×&Ñ& t×'9Ñ'9Õ:Ø�^‰^Ó Ò)Üœ& &Ó)ˆFØ×$Ò$Ø$Ÿnœn�FØ×%Ñ% d×&8Ñ&8Õ9ð -à—‘×(Ñ(¨×);Ñ);Ô<Ø�y‰y×!Ñ!Ó#×*Ñ*¨4¯;©;×+?Ñ+?Ó@ˆØ�	‰	�‰˜ÕrR   c                ó   — | j                   j                  d«       | j                  j                  dkD  r%| j                  j	                  | j                   «       | j                   j                  d«       | j                   j                  «        y)z¥Safe closing of exported DXF file. Copying of OBJECTS section
        happens only at closing the file, without closing the new DXF file is
        invalid.
        s     0
ENDSEC
rD   s
     0
EOF
N)rL   rr   r¨   rd   ry   r”   rb   s    rP   r”   zIterDXFWriter.close   s\   € ð
 	�	‰	�‰Ð,Ô-Ø�;‰;×!Ñ! HÒ,Ø�K‰K×,Ñ,¨T¯Y©YÔ7Ø�	‰	�‰Ð)Ô*Ø�	‰	�‰ÕrR   N)rO   r—   r¨   r>   )rl   r‹   )rƒ   r   )r�   rž   rŸ   rQ   rj   rr   r”   r¢   rR   rP   rf   rf   Ï   s   „ óóó$óL	rR   rf   c                ó   — t        | |¬«      S )u¿  Open DXF file for iterating, be sure to open valid DXF files, no DXF
    structure checks will be applied.

    Use this function to split up big DXF files as shown in the example above.

    Args:
        filename: DXF filename of a seekable DXF file.
        errors: specify decoding error handler

            - "surrogateescape" to preserve possible binary data (default)
            - "ignore" to use the replacement char U+FFFD "ï¿½" for invalid data
            - "strict" to raise an :class:`UnicodeDecodeError` exception for invalid data

    Raises:
        DXFStructureError: invalid or incomplete DXF file
        UnicodeDecodeError: if `errors` is "strict" and a decoding error occurs

    r†   )r>   )ÚfilenamerJ   s     rP   r   r     s   € ô& �8 FÔ+Ð+rR   Nc              #  óš  K  — t        t        | «      «      }d}d}d}t        |«      }t        | d|j                  |¬«      5 }t        |«      }	d}
g }t        «       }t        |	«      D ]Ì  }|j                  }|j                  }|r˜|dk(  rgt        |«      rX|d   j                  |v rGt        j                  t        |«      «      } ||«      s!|j                  j                  dk(  r|
r|
–— |}
|g}n|j!                  |«       |dk(  r|dk(  r|
r|
–—  ddd«       yŒµ|d	k(  r|dk(  r
|d
k(  r|dk(  }|}|}ŒÎ 	 ddd«       y# 1 sw Y   yxY w­w)u€  Iterate over all modelspace entities as :class:`DXFGraphic` objects of
    a seekable file.

    Use this function to iterate "quick" over modelspace entities of a DXF file,
    filtering DXF types may speed up things if many entity types will be skipped.

    Args:
        filename: filename of a seekable DXF file
        types: DXF types like ``['LINE', '3DFACE']`` which should be returned,
            ``None`` returns all supported types.
        errors: specify decoding error handler

            - "surrogateescape" to preserve possible binary data (default)
            - "ignore" to use the replacement char U+FFFD "ï¿½" for invalid data
            - "strict" to raise an :class:`UnicodeDecodeError` exception for invalid data

    Raises:
        DXFStructureError: invalid or incomplete DXF file
        UnicodeDecodeError: if `errors` is "strict" and a decoding error occurs

    éÿÿÿÿÚ FÚrt)rB   ra   rJ   Nr   ro   rT   ÚSECTIONrC   )r   rG   r{   rK   ra   r   r   r   rY   r\   r[   r   rV   r   r}   r~   rZ   )r¼   r   rJ   ÚinfoÚ	prev_codeÚ
prev_valueÚentitiesr‚   ÚfpÚtaggerr�   Útagsr€   ÚtagrY   r\   rƒ   s                    rP   r   r   "  sI  è ø€ ô4 œ˜X›Ó'€DØ€IØ€JØ€HÜ& uÓ-€Oä	ˆh˜T¨D¯M©MÀ&Õ	IÈRÜ" 2Ó&ˆØ&*ˆØˆÜ%›ˆä Ö'ˆCØ—8‘8ˆDØ—I‘IˆEÙØ˜1’9Ü˜4”y T¨!¡W§]¡]°oÑ%EÜ!(§¡¬l¸4Ó.@Ó!A˜á -¨fÔ 5Ø &§
¡
× 5Ñ 5¸Ò :ñ  &Ø&,¢Ø%+˜FØ˜5‘Dà—K‘K Ô$Ø˜1’9 ¨(Ò!2ÙØ$šØ÷9 
JÐ	Ið: Ø˜’˜y¨Aš~°*À	Ò2IØ  JÑ.�àˆIØ‰Jñ9 (÷ 
J×	IÑ	Iüs*   ‚?EÁCD?Ä	EÄD?Ä6	EÄ?EÅEc           	   #  óL  K  — d}d}d}d}d}d}t        |«      }	t        | «      D ]{  \  }
}|
dk(  r|dk(  r nl|
d	k(  r|dk(  r|d
k7  r|dk(  } nV|
dk(  r|dk(  rd}nE|
dk(  r|dk(  rd}n8|dk(  rt        |j                  «       «      }d}n|dk(  r|j                  «       }d}|
}Œ} |dk\  rd}d}g }t	        «       }t        t        | ||«      «      D ]Ò  }|j                  }
|j                  }|rž|
dk(  r|dk(  r|r|–—  y|
dk(  rut        |«      rf|d   j                  |	v rUt        t        t        j                  t        |«      «      «      } ||«      s!|j                  j                  dk(  r|r|–— |}|g}n|j!                  |«       Œ»|
d	k(  r|dk(  r
|dk(  r|dk(  }|
}|}ŒÔ y­w)u›  Iterate over all modelspace entities as :class:`DXFGraphic` objects in
    a single pass.

    Use this function to 'quick' iterate over modelspace entities of a **not**
    seekable binary DXF stream, filtering DXF types may speed up things if many
    entity types will be skipped.

    Args:
        stream: (not seekable) binary DXF stream
        types: DXF types like ``['LINE', '3DFACE']`` which should be returned,
            ``None`` returns all supported types.
        errors: specify decoding error handler

            - "surrogateescape" to preserve possible binary data (default)
            - "ignore" to use the replacement char U+FFFD "ï¿½" for invalid data
            - "strict" to raise an :class:`UnicodeDecodeError` exception for invalid data

    Raises:
        DXFStructureError: Invalid or incomplete DXF file
        UnicodeDecodeError: if `errors` is "strict" and a decoding error occurs

    NÚcp1252rD   r¾   r¿   Fr   s   ENDSECrT   s   HEADERs   ENTITIESé	   s   $DWGCODEPAGEÚENCODINGs   $ACADVERÚVERSIONÚAC1021zutf-8ro   rÁ   rC   )r{   Úbinary_taggerr   rˆ   r   r   rY   r\   r[   r   r   r   rV   r   r}   r~   rZ   )Ústreamr   rJ   Úfetch_header_varra   rM   rÃ   rÄ   rÅ   r‚   rY   r\   r�   rÈ   r€   rÉ   rƒ   s                    rP   r   r   g  sà  è ø€ ð6 '+ÐØ€HØ€GØ€IØ€JØ€HÜ& uÓ-€Oä$ VÖ,‰ˆˆeØ�1Š9˜ )Ò+ÙØ�QŠY˜9¨š>¨e°yÒ.@ð  Ñ+ˆHÙØ�QŠY˜5 OÒ3Ø)ÑØ�QŠY˜5 KÒ/Ø(ÑØ Ò+Ü! %§,¡,£.Ó1ˆHØ#ÑØ Ò*Ø—l‘l“nˆGØ#ÐØ‰	ð% -ð( �(ÒØˆà#'€FØ€DÜ!“O€MäœM¨&°(¸FÓCÖDˆØ�x‰xˆØ—	‘	ˆÙØ�qŠy˜U hÒ.ÙØ ’LÙØ�qŠyÜ�t”9  a¡§¡°/Ñ!AÜ!¤*¬g¯l©l¼<ÈÓ;MÓ.NÓO�FÙ(¨Ô0°V·Z±Z×5JÑ5JÈaÒ5Oñ "Ø"(šLØ!'˜Ø�u‘à—‘˜CÔ ØØ�QŠY˜9¨š>¨j¸IÒ.EØ 
Ñ*ˆHàˆ	Ø‰
ñ3 Eùs   ‚F"F$c              #  ó  K  — 	 	 	 t        | j                  «       «      }| j                  «       j	                  d«      }t        ||r|j                  ||¬«      n|«      –— Œ^# t        $ r t        d«      ‚w xY w# t        $ r Y y w xY w­w)NzInvalid group codes   
r†   )r›   Úreadlinerq   r   Úrstripr   rˆ   ÚIOError)rL   ra   rJ   rY   r\   s        rP   rÐ   rÐ   Á  s•   è ø€ ð
 ð	ð?Ü˜4Ÿ=™=›?Ó+�ð —M‘M“O×*Ñ*¨7Ó3ˆEÜØÙ9A�—‘˜X¨f�Ô5Àuóò ð øô ò ?Ü'Ð*<Ó>Ð>ð?ûô ò 	Ùð	üs:   ‚B	†A" ŸAA: Á!B	Á"A7Á7A: Á:	BÂB	ÂBÂB	c                óî   — | rlt         j                  t        | «      «      }d|v r"|j                  d«       |j                  d«       d|v r"|j                  d«       |j                  d«       |S t         }|S )Nr:   r4   r6   r2   r0   )ÚSUPPORTED_TYPESÚintersectionÚsetÚadd)r   Ú	requesteds     rP   r{   r{   Õ  sn   € ÙÜ#×0Ñ0´°U³Ó<ˆ	Ø˜Ñ"Ø�M‰M˜(Ô#Ø�M‰M˜(Ô#Ø�yÑ Ø�M‰M˜(Ô#Ø�M‰M˜(Ô#ð Ðô $ˆ	ØÐrR   r•   )r¼   r—   rJ   rG   rŒ   r>   )Nr–   )r¼   r—   r   r™   rJ   rG   rŒ   rš   )rÑ   r   r   r™   rJ   rG   rŒ   rš   )rL   r   ra   zOptional[str]rJ   rG   rŒ   zIterator[DXFTag])r   r™   rŒ   rœ   )1Ú
__future__r   Útypingr   r   r   r   r   r	   r
   Úior   Úpathlibr   Úezdxf.lldxf.constr   Úezdxf.lldxf.extendedtagsr   r   Úezdxf.lldxf.tagwriterr   Úezdxf.lldxf.taggerr   r   Úezdxf.filemanagementr   Úezdxf.lldxfr   Úezdxf.entitiesr   r   r   r   r   Úezdxf.entities.subentityr   Úezdxf.tools.codepager   Ú__all__rØ   rG   r—   r>   rf   r   r   r   rÐ   r{   r¢   rR   rP   Ú<module>rë      s   ðõ #÷÷ ñ õ Ý Ý /ß 9Ý +ß >Ý .Ý !ç BÓ BÝ "Ý 2Ý +â
=€ò€ðB ��s�Ñ€÷Kñ K÷\:ñ :ôz,ð0 &*Ø#ðBØðBà"ðBð ðBð ó	BðN &*Ø#ðWØðWà"ðWð ðWð ó	Wðx #Ø#ðØ
ðàðð ðð ó	ô(rR   