
    Og_                       d dl mZ d dlmZ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mZ d dlmZ d d	lmZ d d
lmZmZ ddlmZm Z m!Z! ddl"m#Z# ddl$m%Z%m&Z& er d dlm'Z'm(Z( d dl)m*Z* d dl+m,Z, d dlm-Z- d dl.m/Z/ g dZ0 ejb                  d      Z2 ed eddde
jf                  e       edd e
jh                  d d      e      d      Z5 ee5      Z6dZ7dZ8e8d fZ9ejt                   G d! d"e#             Z; ed#d$ ed%      i      Z< ee<      Z=ejt                   G d& d'e;             Z> ed( edd )       edd*)      d+      Z? ee?      Z@ejt                   G d, d-e#             ZAy).    )annotations)TYPE_CHECKINGUnionOptional)SelfN)	validator)SUBCLASS_MARKERDXFKeyErrorDXFValueErrorDXFTypeErrorDXFStructureError)DXFAttrDXFAttributesDefSubclassRETURN_DEFAULTgroup_code_mapping)is_valid_handle)
AuditError)factory
DXFGraphic   )
base_classSubclassProcessor	DXFEntity)	DXFObject)default_copyCopyNotSupported)DXFNamespaceXRecord)AbstractTagWriter)Drawing)Auditor)xref)
DictionaryDictionaryWithDefaultDictionaryVarezdxfAcDbDictionaryi  F)defaultoptionalr   fixeri     )r)   r   r+   )
hard_ownedcloning   i^  ih  c                      e Zd ZdZdZ eee      Zd' fdZ	e
fd(dZd)dZd* fdZd' fdZd'dZ	 d+	 	 	 d, fd	Zd
 Zd- fdZd. fdZd/dZed0d       Zd Zd Zd1dZd2dZd3dZd4dZd5dZeZd+d6dZd7dZ d2dZ!d8dZ"d3dZ#d3dZ$d'dZ%d'dZ&d9d:dZ'd;dZ(d<d Z)d;d!Z*d=d"Z+d9d>d#Z,d? fd$Z-d@d%Z.d' fd&Z/ xZ0S )Ar$   a  AutoCAD maintains items such as mline styles and group definitions as
    objects in dictionaries. Other applications are free to create and use
    their own dictionaries as they see fit. The prefix "ACAD_" is reserved
    for use by AutoCAD applications.

    Dictionary entries are (key, DXFEntity) pairs. DXFEntity could be a string,
    because at loading time not all objects are already stored in the EntityDB,
    and have to be acquired later.

    
DICTIONARYc                V    t         |           t               | _        t        | _        y N)super__init__dict_data
VALUE_CODE_value_codeself	__class__s    ^/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/entities/dictionary.pyr5   zDictionary.__init__c   s    7;v
%    c                   t        |t              sJ | j                  |_        | j                  j                  rQt               }| j                         D ],  \  }}t        |t              s	 |j                  |      ||<   . ||_        yt        | j                        |_        y# t        $ r= |j                  j                  r#t        j                  dt        |       d       n Y w xY w)zCopy hard owned entities but do not store the copies in the entity
        database, this is a second step (factory.bind), this is just real copying.
        copy_strategyzcopy process ignored z% - this may cause problems in AutoCADN)
isinstancer$   r9   dxfr-   r6   itemsr   copyr   settings%ignore_copy_errors_in_linked_entitiesloggerwarningstrr7   )r;   entityrA   datakeyents         r=   	copy_datazDictionary.copy_datah   s     &*---!--88)-D JJL "S c9-"$'HH=H$IS	"  FL

+FL , "(11WW"NN"7CzAf g "	"s   ,B&&AC,+C,c                
   t               }| j                  s|S | j                         D ]W  \  }}t        |t              s|j                  |      }|s+|j                  j                  ||j                  j                  <   Y |S )z,Returns handle mapping for in-object copies.)r6   is_hard_ownerrD   rB   r   getrC   handle)r;   clonehandle_mappingrM   rK   copied_entrys         r=   get_handle_mappingzDictionary.get_handle_mapping   sx    )-!!!!::< 	LKCfi0 99S>L4@4D4D4K4Kvzz001	L r>   c                2   t        |t              sJ t        |   ||       | j                  ryt               }| j                         D ]C  \  }}t        |t              s|j                  |j                  j                        }|s?|||<   E ||_        y)z3Translate resources from self to the copied entity.N)rB   r$   r4   map_resourcesrQ   r6   rD   r   get_reference_of_copyrC   rS   r7   )r;   rT   mappingrL   rM   rK   entity_copyr<   s          r=   rY   zDictionary.map_resources   s    %,,,eW-v::< 	#KCfi0!77

8I8IJK"S		# r>   c                    t         |           | j                         D ]3  \  }}t        |t              s|j
                  s$|j                          5 y r3   )r4   del_source_of_copyrD   rB   r   is_alive)r;   _rK   r<   s      r=   r^   zDictionary.del_source_of_copy   sC    "$ 	,IAv&),))+	,r>   c                6   | j                   j                  sy| j                  }|J |j                  }| j                   j                  }| j                         D ]=  \  }}||j                   _        t        j                  ||       |j                  |       ? y)zCalled by binding a new or copied dictionary to the document,
        bind hard owned sub-entities to the same document and add them to the
        objects section.
        N)
rC   r-   docobjectsrS   rD   ownerr   bind
add_object)r;   rb   object_sectionowner_handler`   rK   s         r=   post_bind_hookzDictionary.post_bind_hook   s    
 xx"" hhxx 	.IAv+FJJLL%%%f-		.r>   c                ~    t         |   |      }|r*|j                  |t        dd      }| j	                  |       |S )Nr   F)log)r4   load_dxf_attribsfast_load_dxfattribsacdb_dictionary_group_codes	load_dict)r;   	processorrC   tagsr<   s       r=   rl   zDictionary.load_dxf_attribs   sI     g&y1110! 2 D NN4 
r>   c                    d }d }t         }|D ]6  \  }}|t        v r|}|}n|t        k(  r|}|s!|s$|| j                  |<   d }d }8 || _        y r3   )r8   SEARCH_CODESKEY_CODEr7   r9   )r;   rq   entry_handledict_key
value_codecodevalues          r=   ro   zDictionary.load_dict   sl    
 	 KD%|# "
$! L'3

8$#	  &r>   c                     t            |       |j                   fd}t               r+t	         |             D ]  \  }} j                  ||        y y )Nc               3     K   j                         D ],  \  } }j                  |      }||j                  s'| |f . y wr3   )rD   rR   r_   )rM   rS   rK   dbr;   s      r=   rD   z(Dictionary.post_load_hook.<locals>.items   sC     #zz| &V%&//v+%&s   *AA	A)r4   post_load_hookentitydblenlist__setitem__)r;   rb   rD   kvr|   r<   s   `    @r=   r}   zDictionary.post_load_hook   sU    s#\\	& t9UW '1  A&' r>   c                    t         |   |       |j                  t        t        j
                         | j                  j                  |ddg       | j                  |       y)(Export entity specific data as DXF tags.r-   r.   N)	r4   export_entity
write_tag2r	   acdb_dictionarynamerC   export_dxf_attribsexport_dictr;   	tagwriterr<   s     r=   r   zDictionary.export_entity   sM    i(_o.B.BC##Ii/HI#r>   c           	     `   | j                   j                         D ]  \  }}|j                  t        |       t	        |t
              rJ|j                  r|j                  j                  }n't        j                  d| dt        |        d       d}|j                  | j                  |        y )NzKey "z"" points to a destroyed entity in z , target replaced by "0" handle.0)r7   rD   r   rt   rB   r   r_   rC   rS   rH   debugrJ   r9   )r;   r   rM   ry   s       r=   r   zDictionary.export_dict   s     ****, 	:JC  3/%+>>!II,,ELLu %!$i[(HJ  E  !1!159	:r>   c                @    t        | j                  j                        S )zReturns ``True`` if the dictionary is hard owner of entities.
        Hard owned entities will be destroyed by deleting the dictionary.
        )boolrC   r-   r;   s    r=   rQ   zDictionary.is_hard_owner  s    
 DHH''((r>   c                6    | j                   j                         S )z3Returns a :class:`KeysView` of all dictionary keys.)r7   keysr   s    r=   r   zDictionary.keys	  s    zz  r>   c              #  `   K   | j                         D ]  }|| j                  |      f  yw)zReturns an :class:`ItemsView` for all dictionary entries as
        (key, entity) pairs. An entity can be a handle string if the entity
        does not exist.
        N)r   rR   r;   rM   s     r=   rD   zDictionary.items  s0     
 99; 	%Ctxx}$$	%s   ,.c                R    || j                   v r| j                   |   S t        |      )zReturn self[`key`].

        The returned value can be a handle string if the entity does not exist.

        Raises:
            DXFKeyError: `key` does not exist

        )r7   r
   r   s     r=   __getitem__zDictionary.__getitem__  s)     $**::c?"c""r>   c                &    | j                  ||      S )a  Set self[`key`] = `entity`.

        Only DXF objects stored in the OBJECTS section are allowed as content
        of :class:`Dictionary` objects. DXF entities stored in layouts are not
        allowed.

        Raises:
            DXFTypeError: invalid DXF type

        )addr;   rM   rK   s      r=   r   zDictionary.__setitem__#  s     xxV$$r>   c                $    | j                  |      S )z\Delete self[`key`].

        Raises:
            DXFKeyError: `key` does not exist

        )remover   s     r=   __delitem__zDictionary.__delitem__0  s     {{3r>   c                    || j                   v S )zReturns `key` ``in`` self.)r7   r   s     r=   __contains__zDictionary.__contains__9  s    djj  r>   c                ,    t        | j                        S )z$Returns count of dictionary entries.)r   r7   r   s    r=   __len__zDictionary.__len__=  s    4::r>   c                :    | j                   j                  ||      S )zReturns the :class:`DXFEntity` for `key`, if `key` exist else
        `default`. An entity can be a handle string if the entity
        does not exist.

        )r7   rR   )r;   rM   r)   s      r=   rR   zDictionary.getC  s     zz~~c7++r>   c                X    | j                   j                         D ]  \  }}||u s|c S  y)z`Returns the DICTIONARY key string for `entity` or an empty string if not
        found.
         )r7   rD   )r;   rK   rM   entrys       r=   find_keyzDictionary.find_keyK  s5     ****, 	JC
	 r>   c                r   t        |t              rt        |      st        d| d|       t        |t              rl| j
                  D| j
                  j                  r.t        j                  dt        |       dt        |               nt        d|j                                || j                  |<   y)a  Add entry (key, value).

        If the DICTIONARY is hard owner of its entries, the :meth:`add` does NOT take
        ownership of the entity automatically.

        Raises:
            DXFValueError: invalid entity handle
            DXFTypeError: invalid DXF type

        zInvalid entity handle #z	 for key NzInvalid entity z in zGraphic entities not allowed: )rB   rJ   r   r   r   rb   
is_loadingrH   rI   r   dxftyper7   r   s      r=   r   zDictionary.addT  s     fc""6*#&=fXYse$TUU
+xx#(;(;
 VT#d)MN #%CFNNDTCU#VWW 

3r>   c                r    | j                  ||       | j                  j                  |j                  _        y)z*Add entry (key, value) and take ownership.N)r   rC   rS   rd   r   s      r=   take_ownershipzDictionary.take_ownershipo  s$    f88??

r>   c                    | j                   }||vrt        |      | j                  rD| j                  J | j	                  |      }| j                  j
                  j                  |       ||= y)z}Delete entry `key`. Raises :class:`DXFKeyError`, if `key` does not
        exist. Destroys hard owned DXF entities.

        N)r7   r
   rQ   rb   r   rc   delete_entity)r;   rM   rL   rK   s       r=   r   zDictionary.removet  si    
 zzd?c""88'''%%c*F HH**62Ir>   c                >    	 | j                   |= y# t        $ r Y yw xY w)zDelete entry `key` if exists. Does not raise an exception if `key`
        doesn't exist and does not destroy hard owned DXF entities.

        N)r7   KeyErrorr   s     r=   discardzDictionary.discard  s$    
	

3 		s    	c                p    | j                   r| j                          | j                  j                          y)z]Delete all entries from the dictionary and destroys hard owned
        DXF entities.
        N)rQ   _delete_hard_owned_entriesr7   clearr   s    r=   r   zDictionary.clear  s)     ++-

r>   c                    | j                   j                  }| j                         D ]'  \  }}t        |t              s|j                  |       ) y r3   )rb   rc   rD   rB   r   r   )r;   rc   rM   rK   s       r=   r   z%Dictionary._delete_hard_owned_entries  sB    ((""::< 	.KC&),%%f-	.r>   c                    | j                   j                  j                  | j                  j                  |      }| j                  ||       |S )zCreate a new sub-dictionary of type :class:`Dictionary`.

        Args:
            key: name of the sub-dictionary
            hard_owned: entries of the new dictionary are hard owned

        )rd   r-   )rb   rc   add_dictionaryrC   rS   r   r;   rM   r-   dxf_dicts       r=   add_new_dictzDictionary.add_new_dict  sE     88##22((//j 3 
 	hr>   c                    | j                   j                  j                  | j                  j                  |      }| j                  ||       |S )zAdd a new :class:`DictionaryVar`.

        Args:
             key: entry name as string
             value: entry value as string

        rd   ry   )rb   rc   add_dictionary_varrC   rS   r   )r;   rM   ry   new_vars       r=   add_dict_varzDictionary.add_dict_var  sE     ((""55((// 6 
 	gr>   c                    | j                   j                  j                  | j                  j                        }| j                  ||       |S )z[Add a new :class:`XRecord`.

        Args:
             key: entry name as string

        rd   )rb   rc   add_xrecordrC   rS   r   )r;   rM   new_xrecords      r=   r   zDictionary.add_xrecord  sD     hh&&22((// 3 
 	k"r>   c                   || vrO| j                   j                  j                  | j                  j                  |      }| j                  ||       |S | j                  |      }t        |      |j                  _        |S )zSet or add new :class:`DictionaryVar`.

        Args:
             key: entry name as string
             value: entry value as string

        r   )	rb   rc   r   rC   rS   r   rR   rJ   ry   )r;   rM   ry   dict_vars       r=   set_or_add_dict_varzDictionary.set_or_add_dict_var  sr     d?xx''::hhooU ; H HHS(#  xx}H!$UHLLr>   c                    t        |t              st        d|j                                | j	                  ||       | j
                  j                  |j
                  _        y)a   Add `obj` and set owner of `obj` to this dictionary.

        Graphical DXF entities have to reside in a layout and therefore can not
        be owned by a :class:`Dictionary`.

        Raises:
            DXFTypeError: `obj` has invalid DXF type

        zinvalid DXF type: N)rB   r   r   r   r   rC   rS   rd   )r;   r   objs      r=   link_dxf_objectzDictionary.link_dxf_object  sH     #y)!3CKKM?CDDsr>   c                    | j                  |      }|| j                  ||      }|S t        |t              st	        dt        |       d|       |S )zYGet entry `key` or create a new :class:`Dictionary`,
        if `Key` not exist.
        )r-   z"expected a DICTIONARY entity, got z
 for key: )rR   r   rB   r$   r   rJ   r   s       r=   get_required_dictzDictionary.get_required_dict  sg     88C=(((DH
 	 Hj1#4S]O:cUS  r>   c                `    | j                   sy t        | 	  |       | j                  |       y r3   )r_   r4   audit _remove_keys_to_missing_entities)r;   auditorr<   s     r=   r   zDictionary.audit  s'    }}g--g6r>   c           
        g }|j                   }|j                  }| j                  j                         D ]Y  \  }}t	        |t
              r||vs ||       $|j                  r"|j                  j                  |vsI ||       R ||       [ |D ]A  }| j                  |= |j                  t        j                  d| dt        |        | |       C y )NzRemoved entry "z" with invalid handle in )rx   message
dxf_entityrL   )appendr~   r7   rD   rB   rJ   r_   rC   rS   fixed_errorr   INVALID_DICTIONARY_ENTRY)r;   r   trashr   r|   rM   r   s          r=   r   z+Dictionary._remove_keys_to_missing_entities  s    ****, 		JC%%?3K99##2-3Ks		  	C

388)#.GD	{S	   	r>   c                t    | j                   sy | j                  r| j                          t        |           y r3   )r_   rQ   r   r4   destroyr:   s    r=   r   zDictionary.destroy  s,    }}++-r>   returnNonerK   r   r   r   )rT   r$   r   zdict[str, str])rT   r   r[   zxref.ResourceMapperr   r   r3   rp   zOptional[SubclassProcessor]r   r   rb   r!   r   r   r   r    r   r   )r   r    )r   r   )rM   rJ   r   r   )rM   rJ   rK   r   r   r   )rM   rJ   r   r   )rM   rJ   r   r   )r   intrM   rJ   r)   Optional[DXFObject]r   r   )rK   r   r   rJ   )rM   rJ   rK   r   )F)rM   rJ   r-   r   r   r$   )rM   rJ   ry   rJ   r   r&   )rM   rJ   r   r   )r   rJ   r   r   r   r   )rM   rJ   r   r$   r   r"   r   r   )r   r"   )1__name__
__module____qualname____doc__DXFTYPEr   r   r   
DXFATTRIBSr5   r   rO   rW   rY   r^   ri   rl   ro   r}   r   r   propertyrQ   r   rD   r   r   r   r   r   countrR   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __classcell__r<   s   @r=   r$   r$   S   s   	 Gz?;J&
 5A ,4,.( 8<	4			&*'$:* ) )!%#% ! E,!6+
".$(7. r>   r$   AcDbDictionaryWithDefaultr)   iT  c                       e Zd ZdZ eeee      Zd fdZ	e
fd fdZd fdZ	 d	 	 	 d fdZd fdZddZdd fdZdd	Zd fd
Z xZS )r%   ACDBDICTIONARYWDFLTc                0    t         |           d | _        y r3   )r4   r5   _defaultr:   s    r=   r5   zDictionaryWithDefault.__init__)  s    -1r>   c                n    t         |   ||       t        |t              sJ | j                  |_        y )Nr@   )r4   rO   rB   r%   r   )r;   rK   rA   r<   s      r=   rO   zDictionaryWithDefault.copy_data-  s1    &>&"7888--r>   c                    |j                   j                  | j                  j                        | _        t
        |   |       y r3   )r~   rR   rC   r)   r   r4   r}   )r;   rb   r<   s     r=   r}   z$DictionaryWithDefault.post_load_hook2  s2     (()9)9:s#r>   c                X    t         |   |      }|r|j                  |t        d       |S )N   )r4   rl   rm   "acdb_dict_with_default_group_codesr;   rp   rC   r<   s      r=   rl   z&DictionaryWithDefault.load_dxf_attribs9  s0     g&y1**30RTUV
r>   c                    t         |   |       |j                  t        t        j
                         | j                  j                  |d       y )Nr)   )r4   r   r   r	   acdb_dict_with_defaultr   rC   r   r   s     r=   r   z#DictionaryWithDefault.export_entityA  s;    i(_.D.I.IJ##Iy9r>   c                $    | j                  |      S r3   )rR   r   s     r=   r   z!DictionaryWithDefault.__getitem__F  s    xx}r>   c                :    t         |   || j                        S )zReturns :class:`DXFEntity` for `key` or the predefined dictionary
        wide :attr:`dxf.default` entity if `key` does not exist or ``None``
        if default value also not exist.

        r)   )r4   rR   r   )r;   rM   r)   r<   s      r=   rR   zDictionaryWithDefault.getI  s     w{3{66r>   c                p    || _         | j                   j                  j                  | j                  _        y)ztSet dictionary wide default entry.

        Args:
            default: default entry as :class:`DXFEntity`

        N)r   rC   rS   r)   )r;   r)   s     r=   set_defaultz!DictionaryWithDefault.set_defaultR  s'      ==,,33r>   c                      fd} j                    j                   j                  s/j                  j                  rj	                  |       n |        t
                  y )Nc                     j                   j                  j                  j                  j                        } j                  |        j                  t        j                  dt               d       y )Nr   z"Created missing default object in .)rx   r   )
rb   rc   add_placeholderrC   rS   r   r   r   CREATED_MISSING_OBJECTrJ   )placeholderr   r;   s    r=   create_missing_default_objectzBDictionaryWithDefault.audit.<locals>.create_missing_default_object]  sb    ((**:::QK[)66<SYKqI   r>   )r   r_   r~   lockedadd_post_audit_jobr4   r   )r;   r   r  r<   s   `` r=   r   zDictionaryWithDefault.audit\  sP    	 == (>(>&&**+HI-/gr>   r   r   r   r3   r   r   )rM   rJ   r   )r)   r   r   r   r   )r   r   r   r   r   r   r   r   r   r5   r   rO   r}   rl   r   r   rR   r   r   r   r   s   @r=   r%   r%   $  sd    #Gz?<RSJ2 5A (
$ 8<4	:
74 r>   r%   DictionaryVariablesr   r   )schemary   c                       e Zd ZdZdZ eee      Ze	dd       Z
e
j                  dd       Z
	 d		 	 	 d
 fdZd fdZ xZS )r&   a  
    DICTIONARYVAR objects are used by AutoCAD as a means to store named values
    in the database for setvar / getvar purposes without the need to add entries
    to the DXF HEADER section. System variables that are stored as
    DICTIONARYVAR objects are the following:

        - DEFAULTVIEWCATEGORY
        - DIMADEC
        - DIMASSOC
        - DIMDSEP
        - DRAWORDERCTL
        - FIELDEVAL
        - HALOGAP
        - HIDETEXT
        - INDEXCTL
        - INDEXCTL
        - INTERSECTIONCOLOR
        - INTERSECTIONDISPLAY
        - MSOLESCALE
        - OBSCOLOR
        - OBSLTYPE
        - OLEFRAME
        - PROJECTNAME
        - SORTENTS
        - UPDATETHUMBNAIL
        - XCLIPFRAME
        - XCLIPFRAME

    DICTIONARYVARc                :    | j                   j                  dd      S )z:Get/set the value of the :class:`DictionaryVar` as string.ry   r   )rC   rR   r   s    r=   ry   zDictionaryVar.value  s     xx||GR((r>   c                N    | j                   j                  dt        |             y )Nry   )rC   setrJ   )r;   rL   s     r=   ry   zDictionaryVar.value  s    Wc$i(r>   c                X    t         |   |      }|r|j                  |t        d       |S )Nr   )r4   rl   rm   acdb_dict_var_group_codesr   s      r=   rl   zDictionaryVar.load_dxf_attribs  s/     g&y1**30I1M
r>   c                    t         |   |       |j                  t        t        j
                         | j                  j                  |ddg       y)r   r  ry   N)r4   r   r   r	   acdb_dict_varr   rC   r   r   s     r=   r   zDictionaryVar.export_entity  s?    i(_m.@.@A##I'/BCr>   )r   rJ   )rL   rJ   r   r   r3   r   r   )r   r   r   r   r   r   r   r  r   r   ry   setterrl   r   r   r   s   @r=   r&   r&   x  sk    < Gz=9J) ) \\) ) 8<4	D Dr>   r&   )B
__future__r   typingr   r   r   typing_extensionsr   loggingezdxf.lldxfr   ezdxf.lldxf.constr	   r
   r   r   r   ezdxf.lldxf.attributesr   r   r   r   r   ezdxf.lldxf.typesr   ezdxf.auditr   ezdxf.entitiesr   r   	dxfentityr   r   r   dxfobjr   rE   r   r   r   r   ezdxf.lldxf.tagwriterr    ezdxf.documentr!   r"   r'   r#   __all__	getLoggerrH   is_integer_boolis_in_integer_ranger   rn   rt   r8   rs   register_entityr$   r   r   r%   r  r  r&    r>   r=   <module>r*     s   # 1 1 "  !   . " . ? ?  047&#
B			7	# // 
 3i33Aq9 	
+!$J 1A 
C  	D D DN %73<  &88N%O " 	EJ E EP #q)B' /}=  	7DI 7D 7Dr>   