
    'j                        d dl mZ d dlZd dlmZmZmZ d dlmZ ddl	m
Z
 ddlmZmZmZ ddlmZ d d	lmZ erd d
lmZ d dlmZ d dlmZ  ej        d          Z	 d!d"dZ	 d#d$dZd%d ZdS )&    )annotationsN)IterableTYPE_CHECKINGOptional)OrderedDict   )DXFStructureError)
group_tagsDXFTagTags)ExtendedTags)factory)Drawing)	DXFEntity)SectionDictezdxfFtaggerIterable[DXFTag]ignore_missing_eofboolreturnr   c                  
 d
fd}d
fd}t                      }g 
d}t          |           D ] }|d         }|dk    rF |            rt          d          t          
          rt                              d	           |g
W|d
k    ri |            rt          d          
d         }t          |          dk     s|d         j        dk    rt          d          |d         }	
||	j        <   g 
|dk    r|rt                              d           d}
                    |            |            rt          d          |s|st          d          |S )a  Divide input tag stream from tagger into DXF structure entities.
    Each DXF structure entity starts with a DXF structure (0, ...) tag,
    and ends before the next DXF structure tag.

    Generated structure:

    each entity is a Tags() object

    {
        # 1. section, HEADER section consist only of one entity
        'HEADER': [entity],
        'CLASSES': [entity, entity, ...],  # 2. section
        'TABLES': [entity, entity, ...],   # 3. section
        ...
        'OBJECTS': [entity, entity, ...],
    }

    {
        # HEADER section consist only of one entity
        'HEADER': [(0, 'SECTION'), (2, 'HEADER'), .... ],
        'CLASSES': [
            [(0, 'SECTION'), (2, 'CLASSES')],
            [(0, 'CLASS'), ...],
            [(0, 'CLASS'), ...]
        ],
        'TABLES': [
            [(0, 'SECTION'), (2, 'TABLES')],
            [(0, 'TABLE'), (2, 'VPORT')],
            [(0, 'VPORT'), ...],
            ... ,
            [(0, 'ENDTAB')]
        ],
        ...
        'OBJECTS': [
            [(0, 'SECTION'), (2, 'OBJECTS')],
            ... ,
        ]
    }

    Args:
        tagger: generates DXFTag() entities from input data
        ignore_missing_eof: raises DXFStructureError() if False and EOF tag is
            not present, set to True only in tests

    Returns:
        dict of sections, each section is a list of DXF structure entities
        as Tags() objects

    r   r   c                 J    t                     r d         d         dk    S dS )Nr   r   SECTIONFlensections   L/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/lldxf/loader.pyinside_sectionz*load_dxf_structure.<locals>.inside_sectionJ   s)    w<< 	31:a=N22u    c                 J    t                     r d         d         dk    S dS )Nr   r   Tr   r   s   r    outside_sectionz+load_dxf_structure.<locals>.outside_sectionO   s)    w<< 	31:a=N22tr"   Fr   r   z&DXFStructureError: missing ENDSEC tag.zFDXF Structure Warning: found tags outside a SECTION, ignored by ezdxf.)r   ENDSECzADXFStructureError: found ENDSEC tag without previous SECTION tag.   r   zSDXFStructureError: missing required section NAME tag (2, name) at start of section.)r   EOFz4DXF Structure Warning: found more than one EOF tags.Tz#DXFStructureError: missing EOF tag.)r   r   )	r   r
   r	   r   loggerwarningcodevalueappend)r   r   r!   r$   sectionseofentitytagsection_headername_tagr   s             @r    load_dxf_structurer3      s   j     
     
 (MMHG
C
 V$$ ## ##Qi.  ~ R'(PQQQ7|| (   hGGM!!   '#   %QZN>""Q&&.*;*@A*E*E'5   &a(H'.HX^$GGJ WUVVVCCNN6""""~ J HIII G) G EFFFOr"   entitiesIterable[Tags]docOptional[Drawing]Iterable[DXFEntity]c              #  \   K   | D ]&}t          j        t          |          |          V  'd S N)r   loadr   )r4   r6   r/   s      r    load_dxf_entitiesr<      sD        6 6l<//5555556 6r"   r-   dictr   Nonec                ,   |j         }dD ]}|| v r| |         }t          t          ||                    D ]]\  }}|j                            d          }|r"||v rt
                              d| d           |||<   t          j        ||           ^d S )N)TABLESCLASSESENTITIESBLOCKSOBJECTShandlez Found non-unique entity handle #z, data validation is required.)	entitydb	enumerater<   dxfgetr(   r)   r   bind)r-   r6   dbnamer   indexr/   rE   s           r    load_and_bind_dxf_contentrN      s    	BF * *8tnG!*+<Wc+J+J!K!K 	* 	*v11 fllNNa6aaa   "(VS))))* *r"   )F)r   r   r   r   r   r   r:   )r4   r5   r6   r7   r   r8   )r-   r=   r6   r   r   r>   )
__future__r   loggingtypingr   r   r   collectionsr   constr	   tagsr
   r   r   extendedtagsr   ezdxf.entitiesr   ezdxf.documentr   r   ezdxf.eztypesr   	getLoggerr(   r3   r<   rN    r"   r    <module>r[      sV   # " " " " "  4 4 4 4 4 4 4 4 4 4 # # # # # # $ $ $ $ $ $ * * * * * * * * * * & & & & & & " " " " " " *&&&&&&(((((())))))		7	#	# :?n n n n nd 8<6 6 6 6 6* * * * * *r"   