
    Og(                    8   d dl mZ d dlmZmZ d dlmZ d dlZd dlm	Z	 d dl
mZmZmZmZmZ d dlmZmZmZ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 m!Z!m"Z" d dlm#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z) d dl*m+Z+ dgZ, ejZ                  d      Z. ed ede	j^                         edd       edd
ee	j`                  e       edd ee	j`                  e       edd e e	jb                  d d      e      d      Z2 ee2      Z3e G d  de             Z4y)!    )annotations)TYPE_CHECKINGOptional)SelfN)	validator)DXFAttrDXFAttributesDefSubclassRETURN_DEFAULTgroup_code_mapping)DXF12SUBCLASS_MARKERDXF2007DXFInternalEzdxfError)
base_classSubclassProcessor	DXFEntity)acdb_symbol_table_record   )register_entity)Auditor)
DXFGraphicBlockEndBlk)DXFNamespaceEntitySpace)BlockLayout)AbstractTagWriter)xrefBlockRecordezdxfAcDbBlockTableRecord   iT  0)defaulti  )r&   
dxfversionr   fixeri  F      )namelayoutexplodescaleunitsc                  0    e Zd ZdZdZ eeee      Z	d fdZ
ddZddZddZ	 d	 	 	 d fdZd fdZdd	Zd fd
Zd fdZ fdZed d       Zed d       Zed d       Zed d       Zed d       Zed d       Zd!dZd!dZd!dZd" fdZ xZS )#r!   zDXF BLOCK_RECORD table entity

    BLOCK_RECORD is the hard owner of all entities in BLOCK definitions, this
    means owner tag of entities is handle of BLOCK_RECORD.

    BLOCK_RECORDc                p    ddl m} t        |            |       | _        d | _        d | _        d | _        y )Nr   r   )ezdxf.entitydbr   super__init__entity_spaceblockendblkblock_layout)selfr   	__class__s     _/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/entities/blockrecord.pyr5   zBlockRecord.__init__g   s3    . (M&*
(,37    c                    || _         || _        | j                  j                  | j                   j                  _        | j                  j                  | j                  j                  _        y N)r7   r8   dxfhandleowner)r:   r7   r8   s      r<   	set_blockzBlockRecord.set_blocks   s@    
#xx

 $r=   c                    || _         y r?   )r6   )r:   r6   s     r<   set_entity_spacezBlockRecord.set_entity_spacey   s
    (r=   c                x    | j                   J || j                  _        || j                   j                  _        y r?   )r7   r@   r+   )r:   r+   s     r<   renamezBlockRecord.rename|   s-    zz%%%"

r=   c                V    t         |   |      }|r|j                  |t               |S r?   )r4   load_dxf_attribssimple_dxfattribs_loaderacdb_blockrec_group_codes)r:   	processorr@   r;   s      r<   rI   zBlockRecord.load_dxf_attribs   s-     g&y1..s4MN
r=   c                ,   t         |   |       |j                  t        k(  rt	        d      |j                  t        t        j                         |j                  t        t        j                         | j                  j                  |g d       y )Nz$Exporting BLOCK_RECORDS for DXF R12.)r+   r,   r/   r-   r.   )r4   export_entityr'   r   r   
write_tag2r   r   r+   acdb_blockrecr@   export_dxf_attribs)r:   	tagwriterr;   s     r<   rN   zBlockRecord.export_entity   sq    i(5('(NOO_.F.K.KL_m.@.@A##		
r=   c                Z   | j                   J | j                  J | j                  | j                  j                          | j                   j	                  |       | j
                  s'| j                  s| j                  j	                  |       | j                  j	                  |       y)zExports the BLOCK entity, followed by all content entities and finally the
        ENDBLK entity, except for the *Model_Space and *Paper_Space blocks, their
        entities are stored in the ENTITIES section.

        N)r7   r8   r9   update_block_flags
export_dxfis_modelspaceis_active_paperspacer6   )r:   rR   s     r<   export_block_definitionz#BlockRecord.export_block_definition   s     zz%%%{{&&&(002

i(""d&?&?((3y)r=   c                   | j                   J d       | j                   j                  J d       t        |   |       | j                  j
                  }|| j                   j                  v sJ d       | j                  |j                  | j                  |       nt        d| d      | j                  |j                  | j                  |       nt        d| d      | j                  D ]  }|j                  ||        y)	z5Register required resources to the resource registry.Nz0BLOCK_RECORD entity must be assigned to documentzentity database requiredzinvalid BLOCK_RECORD handle)	block_keyzBLOCK entity in BLOCK_RECORD #z is invalidzENDBLK entity in BLOCK_RECORD #)docentitydbr4   register_resourcesr@   rA   r7   
add_entityr   r8   r6   )r:   registrykeyer;   s       r<   r]   zBlockRecord.register_resources   s   xx#W%WW#xx  ,H.HH,"8,hhoodhh'''F)FF'::!

c:'0[A  ;;"s;'1#kB  "" 	2AS1	2r=   c                2   t        |t              sJ t        |   ||       | j                  J |j                  | j                         | j                  J |j                  | j                         | j                  D ]  }|j                  |        y)z3Translate resources from self to the copied entity.N)
isinstancer!   r4   map_resourcesr7   map_resources_of_copyr8   r6   )r:   clonemappingentityr;   s       r<   rd   zBlockRecord.map_resources   s    %---eW-zz%%%%%djj1{{&&&%%dkk2'' 	2F))&1	2r=   c                    | j                   sy| j                  j                          | j                  j                          | j                  D ]  }|j                           | `| `| `t        | 	          y)aA  Destroy associated data:

            - BLOCK
            - ENDBLK
            - all entities stored in this block definition

        Does not destroy the linked LAYOUT entity, this is the domain of the
        :class:`Layouts` object, which also should initiate the destruction of
        'this' BLOCK_RECORD.

        N)is_aliver7   destroyr8   r6   r9   r4   )r:   rh   r;   s     r<   rk   zBlockRecord.destroy   sj     }}

'' 	FNN	 JKr=   c                P    | j                   j                  j                         dk(  S )z*``True`` if is "active" paperspace layout.*paper_spacer@   r+   lowerr:   s    r<   rW   z BlockRecord.is_active_paperspace         xx}}""$66r=   c                h    | j                   j                  j                         j                  d      S )z-``True`` if is any kind of paperspace layout.rm   )r@   r+   ro   
startswithrp   s    r<   is_any_paperspacezBlockRecord.is_any_paperspace   s&     xx}}""$//??r=   c                P    | j                   j                  j                         dk(  S )z%``True`` if is the modelspace layout.z*model_spacern   rp   s    r<   rV   zBlockRecord.is_modelspace   rq   r=   c                6    | j                   xs | j                  S )z;``True`` if is any kind of modelspace or paperspace layout.)rV   rt   rp   s    r<   is_any_layoutzBlockRecord.is_any_layout   s     !!;T%;%;;r=   c                    | j                    S )zn``True`` if not any kind of modelspace or paperspace layout, just a
        regular block definition.
        )rw   rp   s    r<   is_block_layoutzBlockRecord.is_block_layout   s    
 %%%%r=   c                t    | j                   ,t        | j                   j                  j                  dz        S y)zD``True`` if represents an XREF (external reference) or XREF_OVERLAY.   F)r7   boolr@   flagsrp   s    r<   is_xrefzBlockRecord.is_xref  s/     ::!

,,r122r=   c           	     <   	 |j                  | j                  j                  t        | j                               | j                  j                  |       y# t
        $ r: t        j                  dt        |       dt        | j                                Y ^w xY w)zlAdd an existing DXF entity to BLOCK_RECORD.

        Args:
            entity: :class:`DXFGraphic`

        )
paperspacezUnexpected DXF entity z in N)	set_ownerr@   rA   intrt   AttributeErrorloggerdebugstrr7   r6   addr:   rh   s     r<   r^   zBlockRecord.add_entity  s~    	VTXX__T=S=S9TU
 	f%	  	VLL1#f+d3tzz?BSTU	Vs   :A A BBc                    |j                   r.| j                  j                  |       	 |j                  d       yy# t        $ r Y yw xY w)zUnlink `entity` from BLOCK_RECORD.

        Removes `entity` just from  entity space but not from the drawing
        database.

        Args:
            entity: :class:`DXFGraphic`

        N)rj   r6   remover   r   r   s     r<   unlink_entityzBlockRecord.unlink_entity  sK     ??$$V,  &  " s   < 	AAc                F    | j                  |       |j                          y)zDelete `entity` from BLOCK_RECORD entity space and drawing database.

        Args:
            entity: :class:`DXFGraphic`

        N)r   rk   r   s     r<   delete_entityzBlockRecord.delete_entity,  s     	6"r=   c                t    | j                   syt        | 	  |       | j                  j                  |       y)zValidity check. (internal API)N)rj   r4   auditr6   )r:   auditorr;   s     r<   r   zBlockRecord.audit6  s-    }}g(r=   )returnNone)r7   r   r8   r   )r6   r   r   r   )r+   r   r   r   r?   )rL   zOptional[SubclassProcessor]r   r   )rR   r   r   r   )r_   zxref.Registryr   r   )rf   r   rg   zxref.ResourceMapperr   r   )r   r|   )rh   r   r   r   )r   r   r   r   ) __name__
__module____qualname____doc__DXFTYPEr	   r   r   rP   
DXFATTRIBSr5   rC   rE   rG   rI   rN   rX   r]   rd   rk   propertyrW   rt   rV   rw   ry   r~   r^   r   r   r   __classcell__)r;   s   @r<   r!   r!   [   s     Gz+C]SJ
80)# 8<4	
$*2.24 7 7 @ @ 7 7 < < & &  & ") )r=   )5
__future__r   typingr   r   typing_extensionsr   loggingezdxf.lldxfr   ezdxf.lldxf.attributesr   r	   r
   r   r   ezdxf.lldxf.constr   r   r   r   ezdxf.entities.dxfentityr   r   r   ezdxf.entities.layerr   factoryr   ezdxf.auditr   ezdxf.entitiesr   r   r   r   r3   r   ezdxf.layoutsr   ezdxf.lldxf.tagwriterr   r"   r    __all__	getLoggerr   is_valid_block_nameis_integer_boolis_in_integer_rangerP   rK   r!    r=   r<   <module>r      s)   # * "  !   N M 9 $#88+*)7/			7	#Y%B%BC#s+// 
 // 
 3i33Ar: 
+ B /}= ( _)) _) _)r=   