
    hK                       % S r SSKJr  SSKJrJrJrJr  SSKJ	r	J
r
  SSKrSSKrSSKrSSKrSSKrSSKJrJrJr  SSKJr  SSKJr  SS	KJr  SS
KJrJrJr  SSKJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)J*r*J+r+J,r,J-r-J.r.J/r/J0r0J1r1  SSK2J3r3J4r4  SSK5J6r6J7r7  / SQr8\Rr                  " S5      r:Sr;1 Skr<Sr=Sr>\\!/\?4   r@S\AS'   \\B/\4   rCS\AS'   SRS jrD " S S\E5      rF " S S\F5      rG " S S\F5      rH " S S\F5      rI " S S \F5      rJ " S! S"\R                  5      rLSSS# jrMSTSUS% jjrNSVS& jrOS'S(S)S$S*.             SWS+ jjrPSXS, jrQS\R" 5       \LR                  S-.       SYS. jjrTS$S/.     SZS0 jjrUS$S/.     S[S1 jjrVS'S2.S\S3 jjrWS\LR                  4       S]S4 jjrYS\LR                  4       S^S5 jjrZ " S6 S7\	5      r[ " S8 S9\	5      r\ " S: S;5      r] " S< S=\]5      r^S_S> jr_ " S? S@\]5      r` " SA SB\]5      ra " SC SD\]5      rb " SE SF5      rcS`SG jrd " SH SI5      re " SJ SK5      rfSaSL jrgSbSM jrhScSN jriSdSO jrj " SP SQ5      rkg)ezMResource management module for transferring DXF resources between documents.
    )annotations)OptionalSequenceCallableIterable)Protocol	TypeAliasN)const	validatortypes)Tags)DXFInfo)Drawing)
BaseLayout
PaperspaceBlockLayout)is_graphic_entityis_dxf_object	DXFEntityDXFClassfactoryBlockRecordLayerLinetype	TextstyleDimStyleUCSTableEntryMaterial
MLineStyleMLeaderStyleBlockEndBlkInsert	DXFLayoutVisualStyle)CopyStrategyCopySettings)UVecVec3)defineattachembeddetachwrite_blockload_modelspaceload_paperspaceRegistryResourceMapperConflictPolicyLoaderdxf_infor   	XrefErrorXrefDefinitionErrorEntityErrorLayoutErrorezdxf0>   BYBLOCKBYLAYER
CONTINUOUSSTANDARDr	   FilterFunctionLoadFunctionc                @    U  H  n[         R                  U5        M     g N)loggerdebug)messagesmsgs     </var/www/html/env/lib/python3.13/site-packages/ezdxf/xref.py_log_debug_messagesrI   J   s    S     c                      \ rS rSrSrSrg)r6   O   z"base exception for the xref module N)__name__
__module____qualname____firstlineno____doc____static_attributes__rM   rJ   rH   r6   r6   O   s    ,rJ   r6   c                      \ rS rSrSrg)r7   U   rM   NrN   rO   rP   rQ   rS   rM   rJ   rH   r7   r7   U       rJ   r7   c                      \ rS rSrSrg)r8   Y   rM   NrV   rM   rJ   rH   r8   r8   Y   rW   rJ   r8   c                      \ rS rSrSrg)r9   ]   rM   NrV   rM   rJ   rH   r9   r9   ]   rW   rJ   r9   c                      \ rS rSrSrg)InternalErrora   rM   NrV   rM   rJ   rH   r]   r]   a   rW   rJ   r]   c                  ~    \ rS rSrSr\R                  " 5       r\R                  " 5       r\R                  " 5       r	Sr
g)r3   e   a  These conflict policies define how to handle resource name conflicts.

.. versionadded:: 1.1

Attributes:
    KEEP: Keeps the existing resource name of the target document and ignore the
        resource from the source document.
    XREF_PREFIX: This policy handles the resource import like CAD applications by
        **always** renaming the loaded resources to `<xref>$0$<name>`, where `xref`
        is the name of source document, the `$0$` part is a number to create a
        unique resource name and `<name>` is the name of the resource itself.
    NUM_PREFIX: This policy renames the loaded resources to `$0$<name>` only if the
        resource `<name>` already exists. The `$0$` prefix is a number to create a
        unique resource name and `<name>` is the name of the resource itself.

rM   N)rN   rO   rP   rQ   rR   enumautoKEEPXREF_PREFIX
NUM_PREFIXrS   rM   rJ   rH   r3   r3   e   s*    " 99;D))+KJrJ   r3   c                   [        U 5      n [        R                  " U 5      (       a<  [        U S5       nUR	                  S5      nSSS5        [        R
                  " W5      $ [        R                  " U 5      (       a+  [        U SSS9 n[        R                  " U5      sSSS5        $ [        S5      e! , (       d  f       Nu= f! , (       d  f       g= f)zScans the HEADER section of a DXF document and returns a :class:`DXFInfo`
object, which contains information about the DXF version, text encoding, drawing
units and insertion base point.

Raises:
    IOError: not a DXF file or a generic IO error

rbi    Nrtignore)errorszNot a DXF files.)	strr   is_binary_dxf_fileopenreadbinary_dxf_infois_dxf_filer5   IOError)filenamefpdatas      rH   r5   r5   |   s     8}H##H--(D!R774=D " ((..X&&(D2b%%b) 32 ()) "! 32s   B4	C4
C
CFc                    XR                   ;   a  [        SU S35      eU R                   R                  U[        U5      US.S9  g)ay  Add an external reference (xref) definition to a document.

XREF attachment types:

- attached: the XREF that's inserted into this drawing is also present in a
  document to which this document is inserted as an XREF.
- overlay: the XREF that's inserted into this document is **not** present in a
  document to which this document is inserted as an XREF.

Args:
    doc: host document
    block_name: name of the xref block
    filename: external reference filename
    overlay: creates an XREF overlay if ``True`` and an XREF attachment otherwise

Raises:
    XrefDefinitionError: block with same name exist

.. versionadded:: 1.1

zblock 'z' already exist)flags	xref_path)name
dxfattribsN)blocksr7   newmake_xref_flags)doc
block_namerr   overlays       rH   r*   r*      sJ    , ZZ!GJ<"GHHJJNN$W-!
  rJ   c                    U (       a!  [         R                  [         R                  -  $ [         R                  [         R                  -  $ rC   )r
   BLK_XREF_OVERLAYBLK_EXTERNALBLK_XREFr   s    rH   r|   r|      s1    %%(:(:::~~ 2 222rJ   )r   r   r         ?g        )insertscalerotationr   c                   [        XX&S9  [        5       nU(       a  [        U5      US'   US:w  a  [        U5      nXGS'   XGS'   XGS'   [        U5      nU R	                  5       n	U	R                  XUS9$ )aB  Attach the file `filename` to the host document as external reference (XREF) and
creates a default block reference for the XREF in the modelspace of the document.
The function raises an :class:`XrefDefinitionError` exception if the block definition
already exist, but an XREF can be inserted multiple times by adding additional block
references::

    msp.add_blockref(block_name, insert=another_location)

.. important::

    If the XREF has different drawing units than the host document, the scale
    factor between these units must be applied as a uniform scale factor to the
    block reference!  Unfortunately the XREF drawing units can only be detected by
    scanning the HEADER section of a document by the function :func:`dxf_info` and
    is therefore not done automatically by this function.
    Advice: always use the same units for all drawings of a project!

Args:
    doc: host DXF document
    block_name: name of the XREF definition block
    filename: file name of the XREF
    insert: location of the default block reference
    scale: uniform scaling factor
    rotation: rotation angle in degrees
    overlay: creates an XREF overlay if ``True`` and an XREF attachment otherwise

Returns:
    Insert: default block reference for the XREF

Raises:
    XrefDefinitionError: block with same name exist

.. versionadded:: 1.1

r   r   r   xscaleyscalezscale)r   ry   )r*   dictfloatr)   
modelspaceadd_blockref)
r}   r~   rr   r   r   r   r   ry   locationmsps
             rH   r+   r+      sz    Z 3H6J!&x
:|e$8$8$8F|H
..
CJJOOrJ   c                   [         R                  " U 5      nUR                  5       (       a  U$ UR                  nU Hn  nUR	                  5       (       d  UR
                  nUR                  5       nXP-  nUR                  5       (       a  Us  $ XS-  nUR                  5       (       d  Ml  Us  $    [         R                  " U 5      $ )zReturns the path of the XREF file.

Args:
    xref_filename: filename of the XREF, absolute or relative path
    search_paths: search paths where to look for the XREF file

.. versionadded:: 1.1

)pathlibPathexistsrx   is_dirparentresolve)xref_filenamesearch_pathsfilepathrx   pathsearch_paths         rH   	find_xrefr   4  s     ||M*H==D{{}};;Dlln.??O%??O  <<&&rJ   )load_fnr   conflict_policyc               4   [        U [        5      (       d   S5       eU R                  nUc   S5       eU R                  n[        U[        5      (       d   eUR
                  (       d  [        S5      eUR                  R                  SS5      nU(       d  [        S5      eU Vs/ s H  n[        R                  " U5      PM     nnUR                  SUR                  5       5        [        Xh5      n	U	R                  5       (       d  [        S	U	 S
35      eU(       a  U" [!        U	5      5      n
O["        R$                  " U	5      n
U
R&                  UR&                  :  a  [(        R*                  " S5      e[-        XUS9nUR/                  U 5        UR1                  U R2                  S9  UR5                  [(        R6                  [(        R8                  -  SS9  U
R:                  R                  S5      nU(       a  [=        U5      UR                  l        ggs  snf )a  Loads the modelspace of the XREF as content into a block layout.

The loader function loads the XREF as `Drawing` object, by default the
function :func:`ezdxf.readfile` is used to load DXF files. To load DWG files use the
:func:`~ezdxf.addons.odafc.readfile` function from the :mod:`ezdxf.addons.odafc`
add-on. The :func:`ezdxf.recover.readfile` function is very robust for reading DXF
files with errors.

If the XREF path isn't absolute the XREF is searched in the folder of the host DXF
document and in the `search_path` folders.

Args:
    xref: :class:`BlockLayout` of the XREF document
    load_fn: function to load the content of the XREF as `Drawing` object
    search_paths: list of folders to search for XREFS, default is the folder of the
        host document or the current directory if no filepath is set
    conflict_policy: how to resolve name conflicts

Raises:
    XrefDefinitionError: argument `xref` is not a XREF definition
    FileNotFoundError: XREF file not found
    DXFVersionError: cannot load a XREF with a newer DXF version than the host
        document, try the :mod:`~ezdxf.addons.odafc` add-on to downgrade the XREF
        document or upgrade the host document

.. versionadded:: 1.1

z!expected BLOCK definition of XREFNvalid DXF document requiredz(argument 'xref' is not a XREF definitionrw    zno xref path definedr   zfile not found: ''zCcannot embed a XREF with a newer DXF version into the host documentr   )xref_prefixF)state$INSBASE) 
isinstancer   r}   blockr!   is_xrefr7   dxfgetr   r   r   get_abs_filepathr   r   FileNotFoundErrorrk   r:   readfile
dxfversionr
   DXFVersionErrorr4   r/   executerx   set_flag_stater   r   headerr)   
base_point)xrefr   r   r   
target_docr   rw   p_search_pathsr   
source_docloaderorigins                rH   r,   r,   T  s   F dK((M*MM(J!@#@@!JJEeU####==!"LMMYY]];3I!"899.:;lW\\!_lM;J779:2H??"3H:Q ?@@S]+
^^H-
z444##Q
 	
 JOLF
4 
NNtyyN)	%*<*<<EJ"":.F#F|		 - <s   $ Hr   c               X   U R                   nUc   S5       e[        R                  " UR                  U R                  S9n[        X4[        R                  S9nUR                  XR                  5       5        UR                  5         U R                  UR                  S'   [        XUS9  U$ )a  Write the content of `block` into the modelspace of a new DXF document and
convert `block` to an external reference (XREF).  The new DXF document has to be
written by the caller: :code:`xref_doc.saveas(xref_filename)`.
This way it is possible to convert the DXF document to DWG by the
:mod:`~ezdxf.addons.odafc` add-on if necessary::

    xref_doc = xref.detach(my_block, "my_block.dwg")
    odafc.export_dwg(xref_doc, "my_block.dwg")

It's recommended to clean up the entity database of the host document afterwards::

    doc.entitydb.purge()

The function does not create any block references. These references should already
exist and do not need to be changed since references to blocks and XREFs are the
same.

Args:
    block: block definition to detach
    xref_filename: name of the external referenced file
    overlay: creates an XREF overlay if ``True`` and an XREF attachment otherwise

.. versionadded:: 1.1

r   r   unitsr   r   r   )r}   r:   r{   r   r   r4   r3   rc   load_block_layout_intor   r   r   r   block_to_xref)r   r   r   r   r   r   s         rH   r-   r-     s    8 J!@#@@!j&;&;5;;OJJN<O<OPF
!!%)>)>)@A
NN$)$4$4Jj!%8rJ   c                   U R                  5         U R                  nUc   S5       e[        U5      UR                  l        [        U5      UR                  l        g)zGConvert a block definition into an external reference.

(internal API)
Nzinvalid BlockLayout)delete_all_entitiesr   rk   r   rw   r|   rv   )r   r   r   block_entitys       rH   r   r     sQ     
;;L#:%::#!$]!3L,W5LrJ   )r   c                  [        U 5      S:X  a  [        R                  " 5       $ [        S U  5       5      (       a  [	        S5      eU S   R
                  nUc   S5       e[        R                  " UR                  UR                  S9n[        X#5      nUR                  [        XR                  5       5      5        UR                  5         [        U5      UR                  S'   U$ )a_  Write `entities` into the modelspace of a new DXF document.

This function is called "write_block" because the new DXF document can be used as
an external referenced block.  This function is similar to the WBLOCK command in CAD
applications.

Virtual entities are not supported, because each entity needs a real database- and
owner handle.

Args:
    entities: DXF entities to write
    origin: block origin, defines the point in the modelspace which will be inserted
        at the insert location of the block reference

Raises:
    EntityError: virtual entities are not supported

.. versionadded:: 1.1

r   c              3  P   #    U  H  oR                   R                  S L v   M     g 7frC   )r   owner).0es     rH   	<genexpr>write_block.<locals>.<genexpr>  s     
1155;;$s   $&z"virtual entities are not supportedz expected a valid source documentr   r   )lenr:   r{   anyr8   r}   r   r   r4   add_commandLoadEntitiesr   r   r)   r   )entitiesr   r   r   r   s        rH   r.   r.     s    * 8}yy{

1
111>??!J!E#EE!j&;&;:CSCSTJJ+F
|H.C.C.EFG
NN$(LJj!rJ   c                V    [        XUS9nUR                  US9  UR                  5         g)a  Loads the modelspace content of the source document into the modelspace
of the target document.  The filter function `filter_fn` gets every source entity as
input and returns ``True`` to load the entity or ``False`` otherwise.

Args:
    sdoc: source document
    tdoc: target document
    filter_fn: optional function to filter entities from the source modelspace
    conflict_policy: how to resolve name conflicts

.. versionadded:: 1.1

r   	filter_fnN)r4   r/   r   )sdoctdocr   r   r   s        rH   r/   r/     s+    & D@F
Y/
NNrJ   c                    U R                   UL a  [        S5      e[        U R                   XS9nUR                  XS9  UR	                  5         g)a  Loads the paperspace layout `psp` into the target document.  The filter function
`filter_fn` gets every source entity as input and returns ``True`` to load the
entity or ``False`` otherwise.

Args:
    psp: paperspace layout to load
    tdoc: target document
    filter_fn: optional function to filter entities from the source paperspace layout
    conflict_policy: how to resolve name conflicts

.. versionadded:: 1.1

z8Source paperspace layout cannot be from target document.r   r   N)r}   r9   r4   load_paperspace_layoutr   )pspr   r   r   r   s        rH   r0   r0     sF    & ww$TUUCGGTCF
!!#!;
NNrJ   c                  t    \ rS rSr\4SS jjrSS jrSS jrSS jrSS jr	SS jr
SS jrSS	 jrSS
 jrSrg)r1   i'  c                    g rC   rM   )selfentity	block_keys      rH   
add_entityRegistry.add_entity(      rJ   c                    g rC   rM   )r   block_records     rH   	add_blockRegistry.add_block+  r   rJ   c                    g rC   rM   r   handles     rH   
add_handleRegistry.add_handle.  r   rJ   c                    g rC   rM   r   rx   s     rH   	add_layerRegistry.add_layer1  r   rJ   c                    g rC   rM   r   s     rH   add_linetypeRegistry.add_linetype4  r   rJ   c                    g rC   rM   r   s     rH   add_text_styleRegistry.add_text_style7  r   rJ   c                    g rC   rM   r   s     rH   add_dim_styleRegistry.add_dim_style:  r   rJ   c                    g rC   rM   r   s     rH   add_block_nameRegistry.add_block_name=  r   rJ   c                    g rC   rM   r   s     rH   	add_appidRegistry.add_appid@  r   rJ   rM   Nr   r   r   rk   returnNoner   r   r   r  r   zOptional[str]r   r  rx   rk   r   r  )rN   rO   rP   rQ   NO_BLOCKr   r   r   r   r   r   r   r   r   rS   rM   rJ   rH   r1   r1   '  s2    =E rJ   r1   c                      \ rS rSrSSS jjrSS jrSS jrSS jrSS jrSS jr	SS jr
SS	 jrSSS
 jjr        SS jrSS.       SS jjrSrg)r2   iD  c                    g rC   rM   r   r   defaults      rH   
get_handleResourceMapper.get_handleE  r   rJ   c                    g rC   rM   r   s     rH   get_reference_of_copy$ResourceMapper.get_reference_of_copyH  r   rJ   c                    g rC   rM   r   s     rH   	get_layerResourceMapper.get_layerK  r   rJ   c                    g rC   rM   r   s     rH   get_linetypeResourceMapper.get_linetypeN  r   rJ   c                    g rC   rM   r   s     rH   get_text_styleResourceMapper.get_text_styleQ  r   rJ   c                    g rC   rM   r   s     rH   get_dim_styleResourceMapper.get_dim_styleT  r   rJ   c                    g rC   rM   r   s     rH   get_block_nameResourceMapper.get_block_nameW  r   rJ   c                    g rC   rM   r   r   s     rH   map_resources_of_copy$ResourceMapper.map_resources_of_copyZ  r   rJ   c                    g rC   rM   )r   tagsnew_owner_handles      rH   map_pointersResourceMapper.map_pointers]  r   rJ   c                    g rC   rM   )r   	dict_name
entry_namer   s       rH   map_acad_dict_entry"ResourceMapper.map_acad_dict_entry`       	rJ   Foptionalc                   g rC   rM   )r   sourcecloneattrib_namer.  s        rH   map_existing_handle"ResourceMapper.map_existing_handlee  r,  rJ   rM   Nr;   r   rk   r   rk   r   rk   r   Optional[DXFEntity]rx   rk   r   rk   r   r   r   r  r   r#  r   r$  rk   r   r  r(  rk   r)  rk   r   r   r   ztuple[str, DXFEntity]r0  r   r1  r   r2  rk   r   r  )rN   rO   rP   rQ   r
  r  r  r  r  r  r  r   r%  r*  r3  rS   rM   rJ   rH   r2   r2   D  s    *-7@	 RW(1@C	 rJ   r2   c                  (    \ rS rSrSS jrSS jrSrg)LoadingCommandik  c                    g rC   rM   )r   registrys     rH   register_resources!LoadingCommand.register_resourcesl      rJ   c                    g rC   rM   )r   transfers     rH   r   LoadingCommand.executeo  rE  rJ   rM   NrB  r1   r   r  rG  	_Transferr   r  )rN   rO   rP   rQ   rC  r   rS   rM   rJ   rH   r@  r@  k  s    rJ   r@  c                  B    \ rS rSrSr      SS jrS	S jrS
S jrSrg)r   is  z0Loads all given entities into the target layout.c                t    Xl         [        U[        5      (       d  [        S[	        U5       35      eX l        g )Ninvalid target layout type: )r   r   r   r9   typetarget_layout)r   r   rP  s      rH   __init__LoadEntities.__init__v  s5     !-44 <T-=P<QRSS*rJ   c                p    U R                    H&  nUR                  X"R                  R                  S9  M(     g N)r   )r   r   r   r   r   rB  r   s      rH   rC  LoadEntities.register_resources~  s)    AUU[[9 rJ   c                l   U R                   nU R                   Hw  nUR                  U5      nUc  UR                  S[	        U5       35        M6  [        U5      (       a  UR                  U5        MY  UR                  S[	        U5       S35        My     [        U[        5      (       a  [        U5        g g )Nzxref:cannot copy found non-graphic entity  as layout content)
rP  r   get_entity_copyrE   rk   r   r   r   r    _reorganize_paperspace_viewports)r   rG  rP  r   r1  s        rH   r   LoadEntities.execute  s    **mmF,,V4E}!23v;-@A ''((//E
|;MN $ mZ00,]; 1rJ   )r   rP  N)r   Sequence[DXFEntity]rP  r   r   r  rI  rJ  )	rN   rO   rP   rQ   rR   rQ  rC  r   rS   rM   rJ   rH   r   r   s  s,    :+++<F+	+:<rJ   r   c                (   U R                  5       nUc  U R                  5       nU R                  5        H6  nUR                  R                  S:X  d  M  X!Ld  M%  U R                  U5        M8     U R                  UR                  R                  5        g )N   )main_viewportadd_new_main_viewport	viewportsr   iddelete_entityset_current_viewport_handler   )
paperspacemain_vpvps      rH   r[  r[    sr    &&(G224""$6699>b/$$R( % **7;;+=+=>rJ   c                  @    \ rS rSrSrS	S jrS
S jrSS jrSS jrSr	g)LoadPaperspaceLayouti  zLoads a paperspace layout as a new paperspace layout into the target document.
If a paperspace layout with same name already exists the layout will be renamed
to  "<layout name> (x)" where x is 2 or the next free number.
c                t    [        U[        5      (       d  [        S[        U5       35      eXl        X l        g )N invalid paperspace layout type: )r   r   r9   rO  paperspace_layoutr   r   r   r   s      rH   rQ  LoadPaperspaceLayout.__init__  s1    #z** @cLMM!$"rJ   c                    U R                   nU(       a+  U R                   Vs/ s H  o!" U5      (       d  M  UPM     sn$ [        U R                  5      $ s  snf rC   )r   rm  list)r   r   r   s      rH   source_entities$LoadPaperspaceLayout.source_entities  sH    NN	#55F5!1A5FF..// Gs
   AAc                    UR                  U R                  R                  5        U R                  R                  nU R	                  5        H  nUR                  X2S9  M     g rT  )r   rm  
dxf_layout
layout_keyrr  )r   rB  r   r   s       rH   rC  'LoadPaperspaceLayout.register_resources  sQ    D22==>**55	%%'A7 (rJ   c                   U R                   R                  nUR                  UR                  R                  5      n[        U[        5      (       d   eUR                  R                  R                  UR                  R                  5      nU R                  5        H\  nUR                  U5      nU(       a#  [        U5      (       a  UR                  U5        M>  UR                  S[!        U5       S35        M^     [#        U5        g )NrX  rY  )rm  ru  r  r   r   r   r$   rB  r   rf  rx   rr  rZ  r   r   rE   rk   r[  )r   rG  source_dxf_layouttarget_dxf_layoutrP  r   r1  s          rH   r   LoadPaperspaceLayout.execute  s     22==$::;L;P;P;W;WX+Y7777 ))44??!!&&
 **,F,,V4E*511((//E
|;MN - 	)7rJ   )r   rm  Nr   r   r   Optional[FilterFunction]r   r  )r   list[DXFEntity]rI  rJ  )
rN   rO   rP   rQ   rR   rQ  rr  rC  r   rS   rM   rJ   rH   rj  rj    s    
#088rJ   rj  c                  ,    \ rS rSrSrSS jrSS jrSrg)	LoadBlockLayouti  zLoads a block layout as a new block layout into the target document. If a block
layout with the same name exists the conflict policy will be applied.
c                h    [        U[        5      (       d  [        S[        U5       35      eXl        g )Ninvalid block layout type: )r   r   r9   rO  block_layout)r   r   s     rH   rQ  LoadBlockLayout.__init__  s,    %-- ;DK=IJJ!rJ   c                ~    U R                   R                  n[        U[        5      (       a  UR	                  U5        g g rC   )r  r   r   r   r   )r   rB  r   s      rH   rC  "LoadBlockLayout.register_resources  s3    ((55lK00- 1rJ   )r  N)r   r   r   r  rI  rN   rO   rP   rQ   rR   rQ  rC  rS   rM   rJ   rH   r  r    s    "
.rJ   r  c                  ,    \ rS rSrSrSS jrSS jrSrg)	LoadResourcesi  z~Loads table entries into the target document. If a table entry with the same name
exists the conflict policy will be applied.
c                    Xl         g rC   r   )r   r   s     rH   rQ  LoadResources.__init__  s     rJ   c                R    U R                    H  nUR                  U[        S9  M     g rT  )r   r   r  rU  s      rH   rC   LoadResources.register_resources  s#    AX6 rJ   r  N)r   r]  r   r  rI  r  rM   rJ   rH   r  r    s    !7rJ   r  c                      \ rS rSrSr\R                  4     SS jjrSS jr  S     SS jjr	 S     SS jjr
 S       SS jjr    SS	 jr      SS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSSS jjrSrg) r4   i  zLoad entities and resources from the source DXF document `sdoc` into the
target DXF document.

Args:
    sdoc: source DXF document
    tdoc: target DXF document
    conflict_policy: :class:`ConflictPolicy`

c                   [        U[        5      (       d   S5       e[        U[        5      (       d   S5       eXLd   S5       eUR                  UR                  :  a  [        R	                  S5        Xl        X l        X0l        / U l        g )Nz$a valid source document is mandatoryz$a valid target document is mandatoryz-source and target document cannot be the samez>target document has older DXF version than the source document)	r   r   r   rD   warningr   r   r   	_commands)r   r   r   r   s       rH   rQ  Loader.__init__  s     $((P*PP($((P*PP(P!PP??T__,NNP "	!	./1rJ   c                :    U R                   R                  U5        g rC   )r  append)r   commands     rH   r   Loader.add_command   s    g&rJ   Nc                   Uc  U R                   R                  5       nO,[        U[        5      (       d  [	        S[        U5       35      eUR                  U R                   La  [	        S5      eUc$  [        U R                  R                  5       5      nO8U R                  R                  5        Vs/ s H  oB" U5      (       d  M  UPM     nnU R                  [        X15      5        gs  snf )a  Loads the content of the modelspace of the source document into a layout of
the target document, the modelspace of the target document is the default target
layout. The filter function `filter_fn` is used to skip source entities, the
function should return ``False`` for entities to ignore and ``True`` otherwise.

Args:
    target_layout: target layout can be any layout: modelspace, paperspace
        layout or block layout.
    filter_fn: function to filter source entities

NrN  :given target layout does not belong to the target document)r   r   r   r   r9   rO  r}   rq  r   r   r   )r   rP  r   r   r   s        rH   r/   Loader.load_modelspace  s        II002MM:66 <T-=P<QRSSDII-L  DII0023H#'99#7#7#9J#9aYq\#9HJh>? Ks   2C)C)c                    [        U[        5      (       d"  [        R                  " S[	        U5       35      eUR
                  U R                  La  [        S5      eU R                  [        X5      5        g)a7  Loads a paperspace layout as a new paperspace layout into the target document.
If a paperspace layout with same name already exists the layout will be renamed
to  "<layout name> (2)" or "<layout name> (3)" and so on.  The filter function
`filter_fn` is used to skip source entities, the function should return ``False``
for entities to ignore and ``True`` otherwise.

The content of the modelspace which may be displayed through a VIEWPORT entity
will **not** be loaded!

Args:
    psp: the source paperspace layout
    filter_fn: function to filter source entities

rl  >given paperspace layout does not belong to the source documentN)
r   r   r
   DXFTypeErrorrO  r}   r   r9   r   rj  rn  s      rH   r   Loader.load_paperspace_layout!  sd    & #z**$$'GS	{%STT77$))#P  	-c=>rJ   c                   [        U[        5      (       d  [        S[        U5       35      e[        U[        5      (       d  [        S[        U5       35      eUR
                  U R                  La  [        S5      eUR
                  U R                  La  [        S5      eUc  [        U5      nO U Vs/ s H  oS" U5      (       d  M  UPM     nnU R                  [        XB5      5        gs  snf )a"  Loads the content of a paperspace layout into an existing layout of the target
document.  The filter function `filter_fn` is used to skip source entities, the
function should return ``False`` for entities to ignore and ``True`` otherwise.

The content of the modelspace which may be displayed through a
VIEWPORT entity will **not** be loaded!

Args:
    psp: the source paperspace layout
    target_layout: target layout can be any layout: modelspace, paperspace
        layout or block layout.
    filter_fn: function to filter source entities

rl  rN  r  r  N)r   r   r9   rO  r   r}   r   r   rq  r   r   )r   r   rP  r   r   r   s         rH   load_paperspace_layout_into"Loader.load_paperspace_layout_into<  s    ( #z** @cLMM-44 <T-=P<QRSS77$))#P  DII-L  CyH#&73a)A,3H7h>? 8s   4C+C+c                    [        U[        5      (       d  [        S[        U5       35      eUR                  U R
                  La  [        S5      eU R                  [        U5      5        g)a  Loads a block layout (block definition) as a new block layout into the target
document. If a block layout with the same name exists the conflict policy will
be applied.  This method cannot load modelspace or paperspace layouts.

Args:
    block_layout: the source block layout

r  9given block layout does not belong to the source documentN)r   r   r9   rO  r}   r   r   r  )r   r  s     rH   load_block_layoutLoader.load_block_layoutb  sa     ,44 ;D<N;OPQQ499,K  	67rJ   c                   [        U[        5      (       d  [        S[        U5       35      e[        U[        5      (       d  [        S[        U5       35      eUR
                  U R                  La  [        S5      eUR
                  U R                  La  [        S5      eU R                  [        [        U5      U5      5        g)aN  Loads the content of a block layout (block definition) into an existing layout
of the target document.  This method cannot load the content of
modelspace or paperspace layouts.

Args:
    block_layout: the source block layout
    target_layout: target layout can be any layout: modelspace, paperspace
        layout or block layout.

r  rN  r  r  N)r   r   r9   rO  r   r}   r   r   r   r   rq  )r   r  rP  s      rH   r   Loader.load_block_layout_intov  s     ,44 ;D<N;OPQQ-44 <T-=P<QRSS499,K  DII-L  	d<&8-HIrJ   c                v    [        XR                  R                  5      nU R                  [	        U5      5        g)zLoads the layers defined by the argument `names` into the target document.
In the case of a name conflict the conflict policy will be applied.
N)_get_table_entriesr   layersr   r  r   namesr   s      rH   load_layersLoader.load_layers  +     &eYY-=-=>x01rJ   c                v    [        XR                  R                  5      nU R                  [	        U5      5        g)zLoads the linetypes defined by the argument `names` into the target document.
In the case of a name conflict the conflict policy will be applied.
N)r  r   	linetypesr   r  r  s      rH   load_linetypesLoader.load_linetypes  +     &eYY-@-@Ax01rJ   c                v    [        XR                  R                  5      nU R                  [	        U5      5        g)zLoads the TEXT styles defined by the argument `names` into the target document.
In the case of a name conflict the conflict policy will be applied.
N)r  r   stylesr   r  r  s      rH   load_text_stylesLoader.load_text_styles  r  rJ   c                v    [        XR                  R                  5      nU R                  [	        U5      5        g)zLoads the DIMENSION styles defined by the argument `names` into the target
document. In the case of a name conflict the conflict policy will be applied.
N)r  r   	dimstylesr   r  r  s      rH   load_dim_stylesLoader.load_dim_styles  r  rJ   c                v    [        XR                  R                  5      nU R                  [	        U5      5        g)zLoads the MLINE styles defined by the argument `names` into the target
document. In the case of a name conflict the conflict policy will be applied.
N)r  r   mline_stylesr   r  r  s      rH   load_mline_stylesLoader.load_mline_styles  s+     &eYY-C-CDx01rJ   c                v    [        XR                  R                  5      nU R                  [	        U5      5        g)zLoads the MULTILEADER styles defined by the argument `names` into the target
document. In the case of a name conflict the conflict policy will be applied.
N)r  r   mleader_stylesr   r  r  s      rH   load_mleader_stylesLoader.load_mleader_styles  s+     &eYY-E-EFx01rJ   c                v    [        XR                  R                  5      nU R                  [	        U5      5        g)zLoads the MATERIALS defined by the argument `names` into the target
document. In the case of a name conflict the conflict policy will be applied.
N)r  r   	materialsr   r  r  s      rH   load_materialsLoader.load_materials  r  rJ   c           	        [        U R                  U R                  5      n[        R                  R
                  nU R                   H  nUR                  U5        M     U(       a  [        UR                  5        [        U R                  5      nUR                  UR                  5        [        UUR                  UR                  UR                   U R"                  UR$                  S9nU(       a  ['        U5      Ul        UR+                  UR                  5        UR-                  UR.                  5        UR1                  5         UR3                  5         UR5                  5         UR7                  5         UR9                  5         UR;                  5         U R                   H  nUR=                  U5        M     UR?                  5         g)zExecute all loading commands. The `xref_prefix` string is used as XREF name
when the conflict policy :attr:`ConflictPolicy.XREF_PREFIX` is applied.
)rB  copiesobjectshandle_mappingr   copy_errorsN) 	_Registryr   r   r:   optionsrE   r  rC  rI   debug_messagesCopyMachinecopy_blockssource_blocksrK  r  r  r  r   r  rk   r   add_object_copiesregister_classesclassesregister_table_resourcesregister_object_resourcesredirect_handle_mappingmap_object_resourcesmap_entity_resourcescopy_settingsr   finalize)r   r   rB  rE   cmdcpmrG  s          rH   r   Loader.execute  sN    TYY		2##>>C""8, "  7 78$))$../::KK-- 00
 #&{#3H ""3;;/!!#++.))+**,((*%%'%%' >>CKK! "rJ   )r  r   r   r   r   r   r   r   r   r  )r  r@  r   r  )NN)rP  zOptional[BaseLayout]r   r}  r   r  rC   r|  )r   r   rP  r   r   r}  r   r  )r  r   r   r  )r  r   rP  r   r   r  )r  zSequence[str]r   r  r;  )r   rk   r   r  )rN   rO   rP   rQ   rR   r3   rc   rQ  r   r/   r   r  r  r   r  r  r  r  r  r  r  r   rS   rM   rJ   rH   r4   r4     s(    =K<O<O22#*2	2'
 /3.2@+@ ,@ 
	@B /3?? ,? 
	?> /3	$@$@ "$@ ,	$@
 
$@L8!8 
8(J!J "J 
	J:2222222% %rJ   r4   c                    / nU  H/  n UR                  U5      nU(       a  UR                  U5        M/  M1     U$ ! [        R                   a     ML  f = frC   )r   r  r
   DXFTableEntryError)r  tabler   rx   entrys        rH   r  r    sX     "H	IIdOE&   O '' 		s   ):AAc                      \ rS rSrSS jrSS jr\4SS jjrSS jrSS jr	SS jr
SS jrSS	 jrSS
 jrSS jrSS jrSrg)r  i  c                b    Xl         X l        [        0 0U l        [	        5       U l        / U l        g rC   )r   r   r  r  setappidsr  r   r   r   s      rH   rQ  _Registry.__init__  s-     @Hn #)+rJ   c                :    U R                   R                  U5        g rC   r  r  r   rG   s     rH   rE   _Registry.debug      ""3'rJ   c                    Uc   S5       eU R                   R                  U0 5      nUR                  R                  nXC;   a  g XU'   UR	                  U 5        g )Nzinternal error: entity is None)r  
setdefaultr   r   rC  )r   r   r   r   entity_handles        rH   r   _Registry.add_entity  sZ    !C#CC!""--i<

))!%m!!$'rJ   c                
   U R                  U5        UR                  R                  nU R                  UR                  U5        UR                   H  nU R                  X25        M     U R                  UR
                  U5        g rC   )r   r   r   r   entity_spaceendblk)r   r   block_handler   s       rH   r   _Registry.add_block  sc    %#''..**L9"//FOOF1 0++\:rJ   c                   Ub  US:X  a  gU R                   R                  R                  U5      nUc  U R                  SU S35        g[	        U5      (       a  [        S[        U5       35      eU R                  U5        g)zAdd resource by handle (table entry or object), cannot add graphic entities.

Raises:
    EntityError: cannot add graphic entity

Nr;   zsource entity #z does not existzcannot add graphic entity: )r   entitydbr   rE   r   r8   rk   r   )r   r   r   s      rH   r   _Registry.add_handle  sw     >Vs]))--f5>JJ@AV$$ ;CK=IJJrJ   c                    U[         :X  a  g  U R                  R                  R                  U5      nU R	                  U5        g ! [
        R                   a    U R                  SU S35         g f = f)Nzsource layer '' does not exist)DEFAULT_LAYERr   r  r   r   r
   r  rE   )r   rx   layers      rH   r   _Registry.add_layer/  sf    = 	@OO**..t4EOOE"'' 	@JJv-=>?	@s   6A )A0/A0c                   UR                  5       [        ;   a  g  U R                  R                  R	                  U5      nU R                  U5        g ! [        R                   a    U R                  SU S35         g f = f)Nzsource linetype 'r  )	upperDEFAULT_LINETYPESr   r  r   r   r
   r  rE   )r   rx   linetypes      rH   r   _Registry.add_linetype9  sn    ::<,,	C0044T:HOOH%'' 	CJJ*4&0@AB	Cs   6A )A>=A>c                     U R                   R                  R                  U5      nU R                  U5        g ! [        R
                   a    U R                  SU S35         g f = f)Nzsource text style 'r  )r   r  r   r   r
   r  rE   )r   rx   
text_styles      rH   r   _Registry.add_text_styleC  s\    	E//33D9JOOJ''' 	EJJ,TF2BCD	E   69 )A%$A%c                     U R                   R                  R                  U5      nU R                  U5        g ! [        R
                   a    U R                  SU S35         g f = f)Nzsource dimension style 'r  )r   r  r   r   r
   r  rE   )r   rx   	dim_styles      rH   r   _Registry.add_dim_styleJ  s\    	J1155d;IOOI&'' 	JJJ1$7GHI	Jr
  c                     U R                   R                  R                  U5      nU R                  U5        g ! [        R
                   a    U R                  SU S35         g f = f)Nzsource block 'r  )r   block_recordsr   r   r
   r  rE   )r   rx   r   s      rH   r   _Registry.add_block_nameQ  s[    	@??88<<TBLOOL)'' 	@JJv-=>?	@r
  c                V    U R                   R                  UR                  5       5        g rC   )r  addr  r   s     rH   r   _Registry.add_appidX  s    

%rJ   )r  r  r  r   r   Nr  rG   rk   r   r  r   r  r  r  r   r  )rN   rO   rP   rQ   rQ  rE   r  r   r   r   r   r   r   r   r   r   rS   rM   rJ   rH   r  r    sD    ,( >F (; "@CEJ@&rJ   r  c                     \ rS rSr\R
                  S.           S.S jjrS/S jrS0S1S jjrS2S jr	S3S jr
S3S jrS3S	 jrS3S
 jrS3S jrS4S jrS5S jrS6S7S jjr        S8S jrSS.       S9S jjrS:S jrS:S jrS:S jrS:S jrS:S jrS;S jrS:S jrS:S jrS<S jrS=S jrS>S jrS>S jrS?S jr S@S  jr!S@S! jr"SAS" jr#S5S# jr$      SBS$ jr%SCS% jr&SDS& jr'SES' jr(S( r)S) r*S* r+S:S+ jr,S,r-g-)FrK  i\  r   c                   Xl         X l        X0l        X`l        XPl        [        UR                  5      U l        0 U l        0 U l	        0 U l
        0 U l        0 U l        X@l        0 U l        / U l        g rC   )rB  copied_blockscopied_objectsr  r   get_xref_namer   r   layer_mappinglinetype_mappingtext_style_mappingdim_style_mappingblock_name_mappingr  _replace_handlesr  )r   rB  r  r  r  r   r  s          rH   rQ  _Transfer.__init__]  sr     !#%&.()<)<=-/02241324.<02)+rJ   c                :    U R                   R                  U5        g rC   r  r  s     rH   rE   _Transfer.debugw  r  rJ   c                8    U R                   R                  X5      $ rC   )r  r   r  s      rH   r
  _Transfer.get_handlez  s    ""&&v77rJ   c                    U R                   R                  U5      nU(       a/  U R                  R                  R                  R                  U5      $ g rC   )r  r   rB  r   r  )r   r   handle_of_copys      rH   r  _Transfer.get_reference_of_copy}  s?    ,,008==++4488HHrJ   c                8    U R                   R                  X5      $ rC   )r  r   r   s     rH   r  _Transfer.get_layer  s    !!%%d11rJ   c                8    U R                   R                  X5      $ rC   )r  r   r   s     rH   r  _Transfer.get_linetype  s    $$((44rJ   c                8    U R                   R                  X5      $ rC   )r  r   r   s     rH   r  _Transfer.get_text_style      &&**466rJ   c                8    U R                   R                  X5      $ rC   )r  r   r   s     rH   r  _Transfer.get_dim_style  s    %%))$55rJ   c                8    U R                   R                  X5      $ rC   )r  r   r   s     rH   r  _Transfer.get_block_name  r/  rJ   c                     U R                   UR                  R                     UR                  R                     $ ! [         a     gf = f)z%Returns the copy of graphic entities.N)r  r   r   r   KeyErrorr  s     rH   rZ  _Transfer.get_entity_copy  sF    	%%fjj&6&67

8I8IJJ 		s   9< 
A	A	c                    U R                  U5      nU(       a  UR                  X 5        g UR                  R                  U R                  ;   a  g [        SU S35      e)Nzcopy of z
 not found)rZ  map_resourcesr   r   r  r]   )r   r   r1  s      rH   r   _Transfer.map_resources_of_copy  sR    $$V,  -ZZ$"2"22(6(* =>>rJ   c                   [        U5       H  u  p4[        R                  " U5      (       d  M"  U R                  UR                  SS9n[        R
                  " UR                  U5      X'   U(       d  Mh  [        R                  " U5      (       d  M  U R                  R                  R                  R                  U5      nUc  M  X&R                  l        M     g )Nr;   )r	  )	enumerater   is_translatable_pointerr
  valueDXFTagcodeis_hard_ownerrB  r   r  r   r   r   )r   r#  r$  indextagr   copied_objects          rH   r%  _Transfer.map_pointers  s    #D/JE,,S11C@#ll388V<##(;(;C(@(@$(MM$<$<$E$E$I$I&$QM$, .>%%+ *rJ   c                |   U R                   R                  nUR                  R                  U5      nUR	                  U5      n[        U[        5      (       a  U R                  [        R                  :X  a  X&4$ U R                  [        R                  :X  a  [        X R                  U5      nO+U R                  [        R                  :X  a  [        USU5      nU R                  UR                  R                   5      nUc  SU4$ UR#                  X'5        UR                  R                   UR                  l        X'4$ )zTMap and add `entity` to a top level ACAD dictionary `dict_name` in root
dictionary.
r   )rB  r   rootdictget_required_dictr   r   r   r   r3   rc   rd   get_unique_dict_keyr   re   r  r   r   r  r   )r   r(  r)  r   r   	acad_dictexisting_entryloaded_entrys           rH   r*  _Transfer.map_acad_dict_entry  s    }}''MM33I>	"z2 ni00##~':'::!11%%)C)CC0 0 0)
 %%)B)BB0RK
11&**2C2CDv:j/!*!5!5''rJ   Fr-  c               >   UR                   R                  US5      nU(       d  gU R                  U5      nU(       a"  US:w  a  UR                   R                  X65        gU(       a  UR                   R	                  U5        gUR                   R                  US5        g)z_Map handle attribute if the original handle exist and the references entity
was really copied.
r   Nr;   )r   r   r
  r  discard)r   r0  r1  r2  r.  r   
new_handles          rH   r3  _Transfer.map_existing_handle  sm     R0__V,
*+IIMM+2		!!+.		k3/rJ   c                   U R                  5         U R                  [           R                  5        GH5  u  pUR                  R
                  b  M  [        U[        5      (       a  U R                  U5        MG  [        U[        5      (       a  U R                  U5        Mo  [        U[        5      (       a7  UR                  (       a  U R                  U5        M  U R                  U5        M  [        U[        5      (       a  U R!                  U5        M  [        U["        5      (       a  U R%                  X!5        GM  [        U[&        5      (       d  GM$  U R)                  U5        GM8     g)zHRegister copied table-entries in resource tables of the target document.N)register_appidsr  r  itemsr   r   r   r   add_layer_entryr   add_linetype_entryr   is_shape_fileadd_shape_file_entryadd_text_style_entryr   add_dim_style_entryr   add_block_record_entryr   add_ucs_entry)r   source_entity_handler   s      rH   r  "_Transfer.register_table_resources  s    ,0,>,>x,H,N,N,P( zz+ &%(($$V,FH--''/FI..''--f5--f5FH--((0FK00++FIFM22""6*' -QrJ   c                Z   U R                   R                  nU R                  R                  5        H  u  p#[	        U[
        5      (       a  U R                  UR                  U1 SkS9  M9  [	        U[        5      (       a"  U R                  UR                  U[        1S9  Mp  [	        U[        5      (       a"  U R                  UR                  U[        1S9  M  [	        U[        5      (       a  U R                  U5        M  [	        U[        5      (       d  M  U R!                  U5        M     g)zERegister copied objects in object collections of the target document.>   GLOBALr<   r=   )system_entriesN)rB  r   r  rS  r   r   add_collection_entryr  r   r  r?   r    r  r%   add_visualstyle_entryr$   create_empty_paperspace_layout)r   r   _r   s       rH   r  #_Transfer.register_object_resources  s     }}'',,224IA&(++))NN#C * 
 FJ//))%% $ *  FL11))'' $ *  FK00**62FI..33F;5 5rJ   c                     X R                   U'   g rC   )r   )r   
old_target
new_targets      rH   replace_handle_mapping _Transfer.replace_handle_mapping   s    ,6j)rJ   c                    0 nU R                   nU R                  R                  5        H  u  p4XB;   d  M  X$   X'   M     UR                  5        H  u  p5XPR                  U'   M     g)zeRedirect handle mapping from copied entity to a handle of an existing entity
in the target document.
N)r   r  rS  )r   temp_mappingreplace_handlessource_handletarget_handlenew_target_handles         rH   r  !_Transfer.redirect_handle_mapping#  si     (*//,0,?,?,E,E,G(M/.=.L+ -H
 1=0B0B0D,M1B. 1ErJ   c                    U R                   R                  nU R                   R                   H  n UR                  R                  U5        M!     g ! [        R
                   a     M;  f = frC   )rB  r   r  r{   r
   r  )r   r   appids      rH   rR  _Transfer.register_appids2  sT    }}'']]))E& * ++ s   AA)(A)c                b    U R                   R                  R                  R                  U5        g rC   )rB  r   r  register)r   r  s     rH   r  _Transfer.register_classes:  s       ((11':rJ   c                L   U R                   R                  R                  nU R                  R	                  5        Hf  u  p#UR	                  5        HM  u  pEUR                  U5      nUc  [        S5      eUc  M)  UR                  (       d  M<  UR                  XP5        MO     Mh     g )Nz'database error, source entity not found)	rB  r   r  r  rS  r   r]   is_aliver8  )r   	source_dbr   r   r\  r1  source_entitys          rH   r  _Transfer.map_entity_resources=  s    MM,,55	 $ 2 2 8 8 :I/4{{}+$ ).B C ('(QRR$!//< 0= !;rJ   c                   U R                   R                  R                  nU R                  R	                  5        HM  u  p#UR                  U5      nUc  [        S5      eUc  M)  UR                  (       d  M<  UR                  X05        MO     g )Nz'database error, source object not found)	rB  r   r  r  rS  r   r]   ry  r8  )r   rz  source_object_handler1  r{  s        rH   r  _Transfer.map_object_resourcesG  sr    MM,,55	+/+>+>+D+D+F' %MM*>?M$#$MNN U^^^++E8 ,GrJ   c                   U R                   R                  nUR                  R                  R	                  5       nUS;   d  [
        R                  " U5      (       an   UR                  R                  U5      nU(       aK  U R                  UR                  R                  UR                  R                  5        UR                  5         g UR                  R                  nU R                  UR                  U5        UR                  (       a$  UR                  R                  U R                   U'   g g ! [        R                   a    S n Nf = f)N)r;   	DEFPOINTS)rB  r   r   rx   r  r   is_adsk_special_layerr  r   r
   r  ri  r   destroyadd_table_entryry  r  )r   r   r   
layer_namespecialold_names         rH   rT  _Transfer.add_layer_entryP  s    }}''YY^^))+
 ++y/N/N0
 0
++//*5 ++EII,<,<gkk>P>PQ99>>T[[%0>>+099>>Dx(  ++ s   D2 2E
Ec                J   U R                   R                  nUR                  R                  R	                  5       [
        ;   az  UR                  R                  UR                  R                  5      nU R                  UR                  R                  UR                  R                  5        UR                  5         g UR                  R                  nU R                  UR                  U5        UR                  (       a$  UR                  R                  U R                  U'   g g rC   )rB  r   r   rx   r  r  r  r   ri  r   r  r  ry  r  )r   r  r   standardr  s        rH   rU  _Transfer.add_linetype_entryf  s    }}''<<""$(99~~))(,,*;*;<H''(;(;X\\=P=PQ<<$$T^^X6.6ll.?.?D!!(+ rJ   c                    U R                   R                  nUR                  R                  nU R	                  UR
                  U5        UR                  (       a$  UR                  R                  U R                  U'   g g rC   )rB  r   r   rx   r  r  ry  r  )r   r  r   r  s       rH   rX  _Transfer.add_text_style_entryr  s\    }}''>>&&T[[*50:0C0CD##H- rJ   c                R   UR                   R                  nU(       d  g U R                  R                  nUR                  R                  U5      nUc  UR                  R                  U5      nU R                  UR                   R                  UR                   R                  5        g rC   )	r   fontrB  r   r  find_shxadd_shxri  r   )r   r  shape_file_namer   
shape_files        rH   rW  _Transfer.add_shape_file_entryy  sx    $..--}}''[[))/:
,,_=J##JNN$9$9:>>;P;PQrJ   c                    U R                   R                  nUR                  R                  nU R	                  UR
                  U5        UR                  (       a$  UR                  R                  U R                  U'   g g rC   )rB  r   r   rx   r  r  ry  r  )r   r  r   r  s       rH   rY  _Transfer.add_dim_style_entry  s\    }}''==%%T^^Y7/8}}/A/AD""8, rJ   c                `   U R                   R                  nUR                  R                  R	                  5       nUR                  R                  n[        U5      S:  aR  US   S:X  aI  UR                  R                  US   5      UR                  l        UR                  R                  U5        OU R                  UR                  U5        UR                  (       aP  UR                  R                  U R                  U'   U R                  X5        UR                  R                  U5        g g )Nr_  r   *)rB  r   r   rx   r  r   rz   anonymous_block_namer  	add_entryr  ry  r  restore_block_contentr  )r   r   r   r   r~   r  s         rH   rZ   _Transfer.add_block_record_entry  s    }}''!%%**002
##(( z?Q:a=C#7 %)KK$D$DZPQ]$SL!((6
   !3!3\B  0<0@0@0E0ED##H-&&|<KKOOL) !rJ   c           	     f   U R                   R                  U[        5       5      nS nS nUR                  5        H  n[	        U[
        [        45      (       a  [	        U[
        5      (       a  UnM7  UnM;  [        U5      (       a  UR                  U5        M^  UR                  R                  nSU SU S[        U5       3n[        R                  " U5        U R                  U5        M     [	        U[
        5      (       a'  [	        U[        5      (       a  UR                  XE5        g [!        S5      e)Nz1skipping non-graphic DXF entity in BLOCK_RECORD('z', #z): zinvalid BLOCK_RECORD copy)r  r   r   valuesr   r!   r"   r   r   r   rx   rk   loggingr  rE   	set_blockr]   )	r   r   r   contentr   r  r   rx   rG   s	            rH   r  _Transfer.restore_block_content  s    $$((8!%#'nn&F&5&/22fe,,"E#F"6**''/#'',,I$tTZS[[^_bci_j^kl$

3 ' eU##
66(B(B""51 ;<<rJ   c                h    U R                   R                  nU R                  UR                  U5        g rC   )rB  r   r  ucs)r   r  r   s      rH   r[  _Transfer.add_ucs_entry  s%    }}''TXXs+rJ   c                   UR                   R                  nU R                  [        R                  :X  as  UR                  U5      (       a\  UR                  U5      nU R                  UR                   R                  UR                   R                  5        UR                  5         g OU R                  [        R                  :X  a&  [        X0R                  U5      UR                   l        OPU R                  [        R                  :X  a2  UR                  U5      (       a  [        USU5      UR                   l        UR                  U5        g Nr   )r   rx   r   r3   rc   	has_entryr   ri  r   r  rd   get_unique_table_namer   re   r  )r   r  r   rx   rJ  s        rH   r  _Transfer.add_table_entry  s    zz>#6#66t$$!&4++JJ%%~'9'9'@'@   % !!^%?%??3D:J:JERFJJO!!^%>%>>t$$"7b%"H

rJ   c                   UR                   R                  nUR                  5       U;   am  UR                  R	                  U5      nU(       aK  U R                  UR                   R                  UR                   R                  5        UR                  5         g U R                  [        R                  :X  ad  UR	                  U5      nU(       aK  U R                  UR                   R                  UR                   R                  5        UR                  5         g OU R                  [        R                  :X  a&  [        X@R                  U5      UR                   l        OPU R                  [        R                  :X  a2  UR                  U5      (       a  [        USU5      UR                   l        UR                  R!                  UR                   R                  U5        UR                  UR                   l        g r  )r   rx   r  object_dictr   ri  r   r  r   r3   rc   rd   r  r   re   r  r  r   )r   
collectionr  r`  rx   r  rJ  s          rH   ra  _Transfer.add_collection_entry  sZ    yy~~::<>) ,,006G++EII,<,<gkk>P>PQ>#6#66'^^D1N++EII,<,<n>P>P>W>WX  !!^%?%??249I9I:VEIIN!!^%>%>>##D))!6tR!L		""599>>59$++		rJ   c                v   U R                   R                  R                  R                  S5      nUR                  R
                  nUR                  U5      nU(       aK  U R                  UR                  R                  UR                  R                  5        UR                  5         g UR                  X15        g )NACAD_VISUALSTYLE)rB  r   rF  rG  r   descriptionr   ri  r   r  take_ownership)r   visualstylevisualstyle_dictrx   rJ  s        rH   rb  _Transfer.add_visualstyle_entry  s    ==33<<NN
 **)--d3''&&(:(:(A(A !++D>rJ   c                z   U R                   R                  nUR                  R                  5       nUR                  R                  U5      nUR                  UR                  l        UR                  R                  UR                  R                  l
        [        X5      nUR                  R                  U5        g rC   )rB  r   layoutsunique_paperspace_namerz   r{   block_record_handler   r   r   layoutr   append_layout)r   r  r   r~   r  rf  s         rH   rc  (_Transfer.create_empty_paperspace_layout  s    }}'' \\88:
{{z2)5)I)I

&/5zz/@/@!!%%,-
"":.rJ   c                    U R                   R                  R                  nUR                  5        H2  u  p4U(       d  M  UR                  (       d  M!  UR                  U5        M4     g)zEAdd copied DXF objects to the OBJECTS section of the target document.N)rB  r   r  rS  ry  
add_object)r   r  r  rd  objs        rH   r  _Transfer.add_object_copies  sD    --**22llnFAss|||""3' %rJ   c                D    U R                  5         U R                  5         g rC   )copy_raster_varscopy_wipeout_vars)r   s    rH   r  _Transfer.copy_settings  s     rJ   c                   U R                   R                  nU R                   R                  nSUR                  ;  d  SUR                  ;   a  g UR                  R                  5       u  p4nUR                  R                  X4US9  g )NACAD_IMAGE_VARS)framequalityr   )rB  r   r   rF  r  get_raster_variablesset_raster_variables)r   r   r   r  r  r   s         rH   r  _Transfer.copy_raster_vars  si    }}''}}''T]]2 DMM1 $ A A C))e)TrJ   c                    U R                   R                  nU R                   R                  nSUR                  ;  d  SUR                  ;   a  g UR                  R                  UR                  R                  5       S9  g )NACAD_WIPEOUT_VARS)r  )rB  r   r   rF  r  set_wipeout_variablesget_wipeout_frame_settingr  s      rH   r  _Transfer.copy_wipeout_vars!  sb    }}''}}''t}}4"dmm3**,,88: 	+ 	
rJ   c                    U R                   R                  R                  R                  5         U R                   H'  n[
        R                  [        R                  U5        M)     g rC   )	rB  r   r  purger  rD   logr  INFOr  s     rH   r  _Transfer.finalize-  s@      ))//1&&CJJw||S) 'rJ   )r   r  r   r  r  r  r  r  r  r  r  rB  r  r   N)rB  r  r  dict[str, dict[str, DXFEntity]]r  dict[str, DXFEntity]r  zdict[str, str]r  set[str]r   r  r  r5  r6  r7  r9  r   r   r   r8  r:  r;  r<  r=  r>  r  )r  zSequence[DXFClass]r   r  )r   r   r   r  )r  r   r   r  )r  r   r   r  )r  r   r   r  )r   r   r   rk   r   r  )r  r   r   r  )r  r   r`  r  r   r  )r  r%   r   r  )r  r$   r   r  )r  r  r   r  ).rN   rO   rP   rQ   r3   rc   rQ  rE   r
  r  r  r  r  r  r  rZ  r   r%  r*  r3  r  r  ri  r  rR  r  r  r  rT  rU  rX  rW  rY  rZ  r  r[  r  ra  rb  rc  r  r  r  r  r  rS   rM   rJ   rH   rK  rK  \  sq    '++,, 0, &	,
 ', , 
,4(825767?	?((*-(7@(	(< RW00(10@C0	0$+2$<T7C;=9:,
@D	RB*.=,,
 $,!*,<D,	,B?/(!	U

*rJ   rK  c                z    U R                   (       a*  [        R                  " U R                   5      R                  $ gr  )rr   r   r   stem)r}   s    rH   r  r  4  s%    
||||CLL)...rJ   c                N    [        U 5      S:  =(       a    U R                  S5      $ )Nr_  r  )r   
startswith)rx   s    rH   is_anonymous_block_namer  :  s    t9q=1T__S11rJ   c                Z    Sn U SU SU  3nUR                  U5      (       d  U$ US-  nM)  Nr   $r_  )r  )rx   r   r  rA  new_names        rH   r  r  >  sB    E
V1UG1TF+x((O
	 rJ   c                8    Sn U SU SU  3nXB;  a  U$ US-  nM  r  rM   )keyr   
dictionaryrA  new_keys        rH   rH  rH  G  s9    E
F!E7!C5)$N
	 rJ   c                  F    \ rS rSrS	S jrS
S jrSS jrSS jrSS jrSr	g)r  iP  c                    Xl         0 U l        / U l        0 U l        [	        5       U l        [        [        SS95      U l        0 U l	        g )NF)set_source_of_copy)
r   r  r  r  r  r  r&   r'   copy_strategyr  )r   r   s     rH   rQ  CopyMachine.__init__Q  sB    79')-/%(U),%*PQ /1rJ   c                r    UR                  5        H#  u  p#U R                  U5      U R                  U'   M%     g rC   )rS  
copy_blockr  )r   rz   r   r   s       rH   r  CopyMachine.copy_blocks\  s+    #\\^MF"&//%"8DKK ,rJ   c                   0 nU R                   nU R                  nUR                  5        H  u  pV[        U[        5      (       a  U R                  U5        M-  U R                  U5      nUc  MC  [        R                  " Xs5        UR                  R                  XE'   [        US5      (       a*  U R                  R                  UR                  U5      5        [        U5      (       a  XpR                  U'   M  XrU'   M     U$ )Nget_handle_mapping)r   r  rS  r   r   copy_dxf_classcopy_entityr   bindr   r   hasattrupdater  r   r  )r   r   r  r   r  r   r   r1  s           rH   r  CopyMachine.copy_block`  s    '),,#kkmNF&(++##F+$$V,E}LL%%*YY%5%5N"v344##**6+D+DU+KLU##',V$!&v! ," rJ   c                     UR                  U R                  S9$ ! [        R                   a2    U R                  R                  UR                  R                  5         g f = fN)r  )copyr  r
   DXFErrorr  r  r   r   r  s     rH   r  CopyMachine.copy_entityx  sR    	4;;T-?-?;@@~~ 	4  !2!23	4s    AA! A!c                h    U R                   R                  UR                  U R                  S95        g r  )r  r  r  r  )r   clss     rH   r  CopyMachine.copy_dxf_class  s%    CHH43E3EHFGrJ   )r  r  r  r  r  r  r   N)r   r   r   r  )rz   r  r   r  )r   r  r   r  r  )r  r   r   r  )
rN   rO   rP   rQ   rQ  r  r  r  r  rS   rM   rJ   rH   r  r  P  s    	190HrJ   r  )rF   Iterable[str]r   r  )rr   str | os.PathLiker   r   )F)r}   r   r~   rk   rr   rk   r   r  )r   boolr   int)r}   r   r~   rk   rr   rk   r   r(   r   r   r   r   r   r#   )r   rk   r   zSequence[pathlib.Path]r   zpathlib.Path)r   r   r   zOptional[LoadFunction]r   zIterable[pathlib.Path | str]r   r  )r   r   r   r   r   r   )r   r   r   r   r   r  )r   r]  r   r(   r   r   )r   r   r   r   r   r}  r   r  )r   r   r   r   r   r}  r   r  )rf  r   r   r  )r  r  r   r~  )r}   r   r   rk   )rx   rk   r   r  )rx   rk   r   rk   r   rk   )r  rk   r   rk   r   rk   )lrR   
__future__r   typingr   r   r   r   typing_extensionsr   r	   ra   r   r  osr:   ezdxf.lldxfr
   r   r   ezdxf.lldxf.tagsr   ezdxf.lldxf.validatorr   ezdxf.documentr   ezdxf.layoutsr   r   r   ezdxf.entitiesr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   ezdxf.entities.copyr&   r'   
ezdxf.mathr(   r)   __all__	getLoggerrD   r  r  r  r?   r  r@   __annotations__rk   rA   rI   	Exceptionr6   r7   r8   r9   r]   Enumr3   r5   r*   r|   r+   r   tuplerd   r,   r-   r   r.   rc   r/   r0   r1   r2   r@  r   r[  rj  r  r  r4   r  r  rK  r  r  r  rH  r  rM   rJ   rH   <module>r     s/   " 9 9 1    	  / / ! ) " = =     * ; !( 
		7	#8 $i[$%67	 7"C5'>2i 2

		 		) 		) 		) 		I 	TYY .*jB3 8P	8P 8P 	8P
 8P 8P 8P 8Pv'F '+16"..F,
F, $F, /	F, 
F,T FK$$*;$$P FK66'86	6 BK  L +/"''	

 (
 
6 +/"''		
 (
 
4x :$X $N <> <@?(8> (8V.n . 
7N 
7C CL	a& a&HU* U*p20H 0HrJ   