
    Og                        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j0                  d      Z	 d	 	 	 	 	 ddZ	 d	 	 	 	 	 ddZddZy)    )annotationsN)IterableTYPE_CHECKINGOptional)OrderedDict   )DXFStructureError)
group_tagsDXFTagTags)ExtendedTags)factory)Drawing)	DXFEntity)SectionDictezdxfc                :  
 d
fd}d
fd}t               }g 
d}t        |       D ]  }|d   }|dk(  r6 |       rt        d      t        
      rt        j                  d       |g
C|dk(  rY |       rt        d	      
d   }t        |      d
k  s|d   j                  d
k7  rt        d      |d   }	
||	j                  <   g 
|dk(  r|rt        j                  d       d}
j                  |         |       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

    c                 2    t               r d   d   dk(  S y)Nr   r   SECTIONFlensections   W/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/lldxf/loader.pyinside_sectionz*load_dxf_structure.<locals>.inside_sectionJ   s     w<1:a=N22    c                 2    t               r d   d   dk7  S y)Nr   r   Tr   r   s   r   outside_sectionz+load_dxf_structure.<locals>.outside_sectionO   s     w<1:a=N22r   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.)returnbool)	r   r
   r	   r   loggerwarningcodevalueappend)taggerignore_missing_eofr   r   sectionseofentitytagsection_headername_tagr   s             @r   load_dxf_structurer2      sL   j

 (MHG
C
 V$ ##Qi. '(PQQ7|( hGM! '#  %QZN>"Q&.*;*@*@A*E'5  &a(H'.HX^^$GJUVCNN6"G##H  HII) EFFOr   c              #  \   K   | D ]#  }t        j                  t        |      |       % y wN)r   loadr   )entitiesdocr.   s      r   load_dxf_entitiesr8      s-       6ll</556s   *,c                "   |j                   }dD ]~  }|| v s| |   }t        t        ||            D ]Z  \  }}|j                  j	                  d      }|r||v rt
        j                  d| d       |||<   t        j                  ||       \  y )N)TABLESCLASSESENTITIESBLOCKSOBJECTShandlez Found non-unique entity handle #z, data validation is required.)	entitydb	enumerater8   dxfgetr%   r&   r   bind)r,   r7   dbnamer   indexr.   r?   s           r   load_and_bind_dxf_contentrH      s    	BF *8tnG!*+<Wc+J!K 	*v1flNN:6(B`a "(VS)	**r   )F)r*   zIterable[DXFTag]r+   r$   r#   r   r4   )r6   zIterable[Tags]r7   zOptional[Drawing]r#   zIterable[DXFEntity])r,   dictr7   r   r#   None)
__future__r   loggingtypingr   r   r   collectionsr   constr	   tagsr
   r   r   extendedtagsr   ezdxf.entitiesr   ezdxf.documentr   r   ezdxf.eztypesr   	getLoggerr%   r2   r8   rH    r   r   <module>rW      s    #  4 4 # $ * * & "&()			7	# :?nn26nnd 8<66#466*r   