
    hA                       S SK Jr  S SKJrJrJrJrJrJrJ	r	  S SK
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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!  S SK"J#r#  S SK$J%r%  / SQr&1 Skr'\\\(4   r) " S S5      r* " S S5      r+SSS jjr,  S       SS jjr-  S       SS jjr.  S       S S jjr/S!S jr0g)"    )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                      \ rS rSrSrSSS jjr    SS jr\S 5       r\S 5       r	SS jr
SS jr S   SS
 jjr      SS jrS rSrg	)IterDXFA   u  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                   U R                  [        U5      5      u  U l        U l        X l        [        USS9U l        SU R                  ;  a  [        S5      eU R                  R                  S:  a  SU R                  ;  a  [        S5      eg g )NrbmodeENTITIESzENTITIES section not found.AC1009OBJECTSzOBJECTS section not found.)	_load_indexstr	structuresectionserrorsopenfiler   version)selfnamerK   s      F/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/iterdxf.py__init__IterDXF.__init__R   s|    (,(8(8T(C%"4d3	T]]*#$ABB>>!!H,$--1O#$@AA 2P,    c                   [         R                  " U5      n[        5       n/ nUR                   HR  nUR                  S:X  a  UR                  U5        M&  UR                  S:X  d  M8  [        U5      S-
  X5R                  '   MT     XBl        X#4$ )Nr         )r   loaddictindexcodeappendlenvalue)rO   rP   rI   rJ   	new_indexes         rQ   rG   IterDXF._load_index[   su     NN4(	#'6	Avv{  #1$'	NQ$6!	 ! $""rT   c                .    U R                   R                  $ N)rI   encodingrO   s    rQ   rd   IterDXF.encodingj   s    ~~&&&rT   c                .    U R                   R                  $ rc   )rI   rN   re   s    rQ   
dxfversionIterDXF.dxfversionn   s    ~~%%%rT   c                   [        X5      nU R                  R                  U R                  S   S-      R                  nU R
                  R                  S5        U R
                  R                  U5      nUR                  U5        U$ )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

rD   rW   r   )	IterDXFWriterrI   rZ   rJ   locationrM   seekread
write_data)rO   rP   docrl   datas        rQ   exportIterDXF.exportr   sk     D' >>''j(AA(EFOO		qyy~~h't
rT   c                   U R                   S   n U R                  R                  SSU5      nU R                  R
                  U   R                  nU R                  R
                  US-      R                  nXT-
  nU R                  R                  U5        U R                  R                  U5      nUR                  U5        g ! [         a    [	        S5      ef = f)NrF   r   ENDSECz$ENDSEC of OBJECTS section not found.rW   )rJ   rI   get
ValueErrorr   rZ   rl   rM   rm   rn   write)rO   fstart_index	end_indexstart_locationend_locationcountrq   s           rQ   copy_objects_sectionIterDXF.copy_objects_section   s    mmI.	M**1hDI --k:CC~~++IM:CC-		~&yy~~e$	  	M#&JLL	Ms   C CNc              #    #    [        5       nSn[        U5      nU R                  U R                  S   S-   U5       H;  nU" U5      (       a  M  UR                  R
                  S:X  d  M.  U(       a  Uv   UnM=     U(       a  Uv   gg7f)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.

NrD   rW   r   )r   _requested_typesload_entitiesrJ   dxf
paperspace)rO   typeslinked_entityqueuedrequested_typesentitys         rQ   r   IterDXF.modelspace   s     & &*51((MM*%)?
F !((VZZ-B-Ba-G  L
 L s   ABB*Bc              #    ^ #    SU 4S jjnUnT R                   R                  U   nT R                  R                  UR                  5        UR
                  S:w  a  US-  nT R                   R                  U   nUR                  UR                  -
  nT R                  R                  U5      nUR
                  U;   a4  [        R                  " U" U5      5      n	[        R                  " U	5      v   UnUR
                  S:w  a  M  g g 7f)Nc                l   > U R                  TR                  TR                  S9R                  SS5      $ )NrK   z

)decoderd   rK   replace)rq   rO   s    rQ   to_str%IterDXF.load_entities.<locals>.to_str   s0    ;;t}}T[[;AII rT   ru   rW   )rq   bytesreturnrH   )rI   rZ   rM   rm   rl   r^   rn   r   	from_textr   rX   )
rO   startr   r   rZ   entry
next_entrysizerq   xtagss
   `         rQ   r   IterDXF.load_entities   s     	
 $$U+		u~~&kkX%QJE--e4J&&7D99>>$'D{{o-$..vd|<ll5))E kkX%s   DDDc                8    U R                   R                  5         g)zSafe closing source DXF file.N)rM   closere   s    rQ   r   IterDXF.close   s    		rT   )rK   rM   rJ   rI   surrogateescape)rP   FilenamerK   rH   )rP   rH   r   z.tuple[fileindex.FileStructure, dict[str, int]])rP   r   r   rk   )ry   r   r   Nonerc   )r   Optional[Iterable[str]]r   Iterable[DXFGraphic])r   intr   set[str]r   r   )__name__
__module____qualname____firstlineno____doc__rR   rG   propertyrd   rh   rr   r   r   r   r   __static_attributes__ rT   rQ   r>   r>   A   s     B##	7# ' ' & && 04 , 	 D+3	*rT   r>   c                  8    \ rS rSrSS jrS	S jrS
S jrS rSrg)rk      c                    [        U5      U l        [        USS9U l        [	        5       U l        [        U R
                  UR                  5      U l        X l	        g )NwbrB   )
rH   rP   rL   rM   r   textr   rh   entity_writerloader)rO   rP   r   s      rQ   rR   IterDXFWriter.__init__   sB    I	"4d3	J	&tyy&2C2CDrT   c                :    U R                   R                  U5        g rc   )rM   rx   )rO   rq   s     rQ   ro   IterDXFWriter.write_data   s    		rT   c                   U R                   R                  S5        U R                   R                  5         UR                  R                  c  SU R
                  l        UR                  U R
                  5        UR                  5       S:X  ad  [        [        U5      nUR                   H  nUR                  U R
                  5        M      UR                  R                  U R
                  5        OUR                  5       S:X  at  [        [        U5      nUR                  (       aS  UR                   H  nUR                  U R
                  5        M      UR                  R                  U R
                  5        U R                   R!                  5       R#                  U R$                  R&                  5      nU R(                  R+                  U5        g)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   rm   truncater   handler   write_handles
export_dxfdxftyper   r   verticesseqendr   attribs_followattribsgetvalueencoder   rd   rM   rx   )rO   r   polylinevertexinsertattribrq   s          rQ   rx   IterDXFWriter.write   sB   " 			q		::$/4D,$,,->>z)Hf-H"++!!$"4"45 ,OO&&t'9'9:^^)&&)F$$$nnF%%d&8&89 -((););<yy!!#**4;;+?+?@		rT   c                "   U R                   R                  S5        U R                  R                  S:  a%  U R                  R	                  U R                   5        U R                   R                  S5        U R                   R                  5         g)zSafe 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
rE   s
     0
EOF
N)rM   rx   r   rh   r   r   re   s    rQ   r   IterDXFWriter.close   s\    
 			,-;;!!H,KK,,TYY7		)*		rT   )r   rM   r   rP   r   N)rP   r   r   r>   )rq   r   )r   r   )	r   r   r   r   rR   ro   rx   r   r   r   rT   rQ   rk   rk      s    $L	rT   rk   c                    [        XS9$ )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>   )filenamerK   s     rQ   r   r     s    & 8++rT   Nc              #    #    [        [        U 5      5      nSnSnSn[        U5      n[        U SUR                  US9 n[        U5      n	Sn
/ n[        5       n[        U	5       H  nUR                  nUR                  nU(       a  US:X  az  [        U5      (       af  US   R                  U;   aS  [        R                  " [        U5      5      nU" U5      (       d'  UR                  R                  S:X  a  U
(       a  U
v   Un
U/nOUR!                  U5        US:X  a  US:X  a  U
(       a  U
v     SSS5        gM  US	:X  a  US:X  a  US
:X  a  US:H  nUnUnM     SSS5        g! , (       d  f       g= f7f)uD  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)rC   rd   rK   Nr   ru   rV   SECTIONrD   )r   rH   r   rL   rd   r   r   r   r[   r^   r]   r   rX   r   r   r   r\   )r   r   rK   info	prev_code
prev_valueentitiesr   fptaggerr   tagsr   tagr[   r^   r   s                    rQ   r   r   "  sM    4 X'DIJH&u-O	hTDMM&	IR"2&&*%'C88DIIE194yyT!W]]o%E!(l4.@!A -f 5 5 &

 5 5 :  &&,%+F5DKK$19(!2$9 
J	I: yA~*	2I J.IJ9 ( 
J	I	Is)   <E2C0E!.	E27!E!	E2!
E/+E2c           	   #    #    SnSnSnSnSnSn[        U5      n	[        U 5       H  u  pU
S:X  a  US:X  a    OwU
S	:X  a  US:X  a  US
:w  a  US:H  n  O^U
S:X  a	  US:X  a  SnOIU
S:X  a	  US:X  a  SnO:US:X  a  [        UR                  5       5      nSnOUS:X  a  UR                  5       nSnU
nM     US:  a  SnSn/ n[	        5       n[        [        XU5      5       H  nUR                  n
UR                  nU(       a  U
S:X  a  US:X  a  U(       a  Uv     gU
S:X  a  [        U5      (       at  US   R                  U	;   aa  [        [        [        R                  " [        U5      5      5      nU" U5      (       d'  UR                  R                  S:X  a  U(       a  Uv   UnU/nOUR!                  U5        M  U
S	:X  a  US:X  a  US:X  a  US:H  nU
nUnM     g7f)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cp1252rE   r   r   Fr   s   ENDSECrV   s   HEADERs   ENTITIES	   s   $DWGCODEPAGEENCODINGs   $ACADVERVERSIONAC1021zutf-8ru   r   rD   )r   binary_taggerr   r   r   r   r[   r^   r]   r   r   r   rX   r   r   r   r\   )streamr   rK   fetch_header_varrd   rN   r   r   r   r   r[   r^   r   r   r   r   r   s                    rQ   r   r   g  s    6 '+HGIJH&u-O$V,19)+QY9>ey.@ +HQY5O3)QY5K/(+!%,,.1H#*llnG#	% -( (#'FD!OMM&FCDxx		qyUh. Lqyt99a/!A!*gll<;M.NOF(00VZZ5J5Ja5O ""(L!'uC QY9>jI.E
*H	
3 Es   GGc              #    #       [        U R                  5       5      nU R                  5       R	                  S5      n[        UU(       a  UR                  XS9OU5      v   M`  ! [         a    [        S5      ef = f! [         a     g f = f7f)NzInvalid group codes   
r   )r   readlinerw   r   rstripr   r   IOError)rM   rd   rK   r[   r^   s        rQ   r   r     s     
 	?4==?+ MMO**73E9AX5u    ?'*<>>?  		s:   BA$ AA= "B$A::A= =
B
B	B

Bc                    U (       ap  [         R                  [        U 5      5      nSU;   a"  UR                  S5        UR                  S5        SU;   a"  UR                  S5        UR                  S5        U$ [         nU$ )Nr:   r4   r6   r2   r0   )SUPPORTED_TYPESintersectionsetadd)r   	requesteds     rQ   r   r     sn    #00U<	"MM(#MM(#y MM(#MM(#  $	rT   r   )r   r   rK   rH   r   r>   )Nr   )r   r   r   r   rK   rH   r   r   )r   r   r   r   rK   rH   r   r   )rM   r   rd   zOptional[str]rK   rH   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   rH   r   r>   rk   r   r   r   r   r   r   rT   rQ   <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 ##
  	(rT   