
    Ogb                         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
mZmZ ddlmZ erd dlmZ d d	lmZ d d
lmZmZmZmZmZmZ dgZ G d d      Zy)    )annotations)TYPE_CHECKINGUnionOptional)Tags)DXFStructureError)ACAD_XDICTIONARYXDICT_HANDLE_CODEAPP_DATA_MARKER   )default_copy)Drawing)AbstractTagWriter)
Dictionary	DXFEntity	DXFObjectPlaceholderDictionaryVarXRecordExtensionDictc                     e Zd ZdZdZddZedd       Zed d       Zd!dZ	d!dZ
d!dZd!d	Zd
 Zd Zd Zd"d#dZd$dZed%d       Zefd&dZed        Zed        Zd'dZed(d       Zd)dZd*dZd Zd+d,dZd-dZd.dZd/dZ d0dZ!y)1r   aP  Stores extended data of entities in app data 'ACAD_XDICTIONARY', app
    data contains just one entry to a hard-owned DICTIONARY objects, which is
    not shared with other entities, each entity copy has its own extension
    dictionary and the extension dictionary is destroyed when the owner entity
    is deleted from database.

    _xdictc                    || _         y Nr   selfxdicts     Y/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/entities/xdict.py__init__zExtensionDict.__init__,   s         c                f    | j                   }|J d       t        |t              rJ d| d       |S )zBReturns the underlying :class:`~ezdxf.entities.Dictionary` object.destroyed extension dictionaryzdictionary handle #z not resolved)r   
isinstancestrr   s     r   
dictionaryzExtensionDict.dictionary1   sC      B"BB eS)U-@}+UU)r!   c                B    | j                   j                  j                  S )zaReturns the handle of the underlying :class:`~ezdxf.entities.Dictionary`
        object.
        )r&   dxfhandler   s    r   r)   zExtensionDict.handle9   s    
 "")))r!   c                     | j                   |   S )zGet self[key].r&   r   keys     r   __getitem__zExtensionDict.__getitem__@   s    s##r!   c                "    || j                   |<   y)a	  Set self[key] to value.

        Only DXF objects stored in the OBJECTS section are allowed as content
        of the extension dictionary. DXF entities stored in layouts are not
        allowed.

        Raises:
            DXFTypeError: invalid DXF type

        Nr,   )r   r.   values      r   __setitem__zExtensionDict.__setitem__D   s      %r!   c                    | j                   |= y)z-Delete self[key], destroys referenced entity.Nr,   r-   s     r   __delitem__zExtensionDict.__delitem__Q   s    OOC r!   c                    || j                   v S )zReturn `key` in self.r,   r-   s     r   __contains__zExtensionDict.__contains__U   s    doo%%r!   c                ,    t        | j                        S )z.Returns count of extension dictionary entries.)lenr&   r*   s    r   __len__zExtensionDict.__len__Y   s    4??##r!   c                6    | j                   j                         S )z=Returns a :class:`KeysView` of all extension dictionary keys.)r&   keysr*   s    r   r;   zExtensionDict.keys]   s    ##%%r!   c                6    | j                   j                         S )zReturns an :class:`ItemsView` for all extension dictionary entries as
        (key, entity) pairs. An entity can be a handle string if the entity
        does not exist.
        )r&   itemsr*   s    r   r=   zExtensionDict.itemsa   s    
 $$&&r!   Nc                :    | j                   j                  ||      S )z(Return extension dictionary entry `key`.)r&   get)r   r.   defaults      r   r?   zExtensionDict.geth   s    ""300r!   c                8    | j                   j                  |      S )z)Discard extension dictionary entry `key`.)r&   discardr-   s     r   rB   zExtensionDict.discardl   s    &&s++r!   c                L    |j                   j                  |d      } | |      S )NTowner
hard_owned)objectsadd_dictionary)clsowner_handledocr   s       r   newzExtensionDict.newp   s-    ** + 

 5zr!   c                N    |j                  | j                        }t        |      S )zXDeep copy of the extension dictionary all entries are virtual
        entities.
        )copyr&   r   )r   copy_strategy	new_xdicts      r   rN   zExtensionDict.copyy   s#     "&&t7	Y''r!   c                    | j                   duS )znReturns ``True`` if the underlying :class:`~ezdxf.entities.Dictionary`
        object is not deleted.
        Nr   r*   s    r   is_alivezExtensionDict.is_alive   s     {{$&&r!   c                X    | j                   }|t        |t              ry|j                  S )zrReturns ``True`` if the underlying :class:`~ezdxf.entities.Dictionary`
        really exist and is valid.
        F)r   r$   r%   rR   r   s     r   has_valid_dictionaryz"ExtensionDict.has_valid_dictionary   s(    
 =Juc2~~r!   c                `    | j                   sJ d       || j                  j                  _        y)zrUpdate owner tag of underlying :class:`~ezdxf.entities.Dictionary`
        object.

        Internal API.
        r#   N)rR   r&   r(   rE   )r   r)   s     r   update_ownerzExtensionDict.update_owner   s(     }}>>>}$*!r!   c                    |J t        |      dk7  s|d   j                  t        k7  rt        d       | |d   j                        S )N   r   zACAD_XDICTIONARY error.)r8   coder
   r   r1   )rI   tagss     r   	from_tagszExtensionDict.from_tags   sJ     t9>T!W\\->>#$=>>47==!!r!   c                    | j                   }t        |t              sJ |j                  j	                  |      | _         y r   )r   r$   r%   entitydbr?   )r   rK   r)   s      r   load_resourceszExtensionDict.load_resources   s1    &#&&&ll&&v.r!   c                   | j                   J | j                   }t        |t              r|n|j                  j                  }|j                  t        t               |j                  t        |       |j                  t        d       y )N})	r   r$   r%   r(   r)   
write_tag2r   r	   r
   )r   	tagwriterr   r)   s       r   
export_dxfzExtensionDict.export_dxf   sg    {{&&&$UC0eii6F6F_.>?.7_c2r!   c                ^    | j                   r| j                  j                          d| _        y)zBDestroy the underlying :class:`~ezdxf.entities.Dictionary` object.N)rT   r   destroyr*   s    r   re   zExtensionDict.destroy   s"    $$KK!r!   c                    | j                   }|j                  }|J d       |j                  j                  |j                  j
                  |      }|||<   |S )znCreate a new :class:`~ezdxf.entities.Dictionary` object as
        extension dictionary entry `name`.
        valid DXF document requiredrD   )r&   rK   rG   rH   r(   r)   )r   namerF   r&   rK   new_dicts         r   rH   zExtensionDict.add_dictionary   s`     __
nn= ==;;--..''! . 
 $
4r!   c                    | j                   }|j                  }|J d       |j                  j                  |j                  j
                        }|||<   |S )zkCreate a new :class:`~ezdxf.entities.XRecord` object as
        extension dictionary entry `name`.
        rg   )r&   rK   rG   add_xrecordr(   r)   )r   rh   r&   rK   xrecords        r   rk   zExtensionDict.add_xrecord   sS     __
nn= ==++))*..*?*?@"
4r!   c                    | j                   }|j                  }|J d       |j                  j                  |j                  j
                  |      }|||<   |S )zqCreate a new :class:`~ezdxf.entities.DictionaryVar` object as
        extension dictionary entry `name`.
        rg   )r&   rK   rG   add_dictionary_varr(   r)   )r   rh   r1   r&   rK   dict_vars         r   rn   z ExtensionDict.add_dictionary_var   sU     __
nn= ==;;11*..2G2GO#
4r!   c                    | j                   }|j                  }|J d       |j                  j                  |j                  j
                        }|||<   |S )zoCreate a new :class:`~ezdxf.entities.Placeholder` object as
        extension dictionary entry `name`.
        rg   )r&   rK   rG   add_placeholderr(   r)   )r   rh   r&   rK   placeholders        r   rq   zExtensionDict.add_placeholder   sT     __
nn= ==kk11*..2G2GH&
4r!   c                <    | j                   j                  ||       y)aB  Link `obj` to the extension dictionary as entry `name`.

        Linked objects are owned by the extensions dictionary and therefore
        cannot be a graphical entity, which have to be owned by a
        :class:`~ezdxf.layouts.BaseLayout`.

        Raises:
            DXFTypeError: `obj` has invalid DXF type

        N)r&   link_dxf_object)r   rh   objs      r   rt   zExtensionDict.link_dxf_object   s     	''c2r!   )r   zUnion[str, Dictionary])returnr   )rv   r%   )r.   r%   r   )r.   r%   rv   zOptional[DXFEntity])r.   r%   rv   None)rJ   r%   rK   r   )rv   r   )r)   r%   rv   rw   )rZ   r   )rK   r   rv   rw   )rb   r   rv   rw   )T)rh   r%   rF   boolrv   r   )rh   r%   rv   r   )rh   r%   r1   r%   rv   r   )rh   r%   rv   r   )rh   r%   ru   r   rv   rw   )"__name__
__module____qualname____doc__	__slots__r    propertyr&   r)   r/   r2   r4   r6   r9   r;   r=   r?   rB   classmethodrL   r   rN   rR   rT   rV   r[   r^   rc   re   rH   rk   rn   rq   rt    r!   r   r   r   !   s     I
   * *$%!&$&'1,   ". ( ' '  + " "/
3			3r!   N)
__future__r   typingr   r   r   ezdxf.lldxf.tagsr   ezdxf.lldxf.constr   r	   r
   r   rN   r   ezdxf.documentr   ezdxf.lldxf.tagwriterr   ezdxf.entitiesr   r   r   r   r   r   __all__r   r   r!   r   <module>r      sN    # 1 1 ! / 
 &7  
P3 P3r!   