
    h`                       S SK Jr  S SKJrJrJrJrJr  S SKrS SK	J
r
  S SKJr  S SKJrJrJrJrJrJrJrJrJr  \(       a  S SKJr  S SKJrJr  \R8                  " S	5      r/ S
Qr1 Skr " S S5      r SSS jjr!SSS jjr"g)    )annotations)TYPE_CHECKINGIterablecastUnionOptionalN)const)ARROWS)		DXFEntity
DXFGraphicHatchPolylineDimStyle	DimensionViewportLinetypeInsert)Drawing)
BaseLayoutLayoutezdxf)	linetypeslayersstyles	dimstyles>   ARCRAYLINEMESHTEXTHATCHMTEXTPOINTSHAPESOLIDTRACEXLINE3DFACEATTDEFATTRIBCIRCLEINSERTLEADERSPLINEELLIPSEPOLYLINEVIEWPORT	DIMENSION
LWPOLYLINEc                  l   \ rS rSrS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'S j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 jrS.S jrS/S jrS0S jr S*     S1S jjrS*S2S jjrS3S jrS3S jrS4S jrS5S6S jjrS7S8S jjrS rS4S jrS4S jrS rS rS4S jr S r!g)9Importer8   a  
The :class:`Importer` class is central element for importing data from
other DXF documents.

Args:
    source: source :class:`~ezdxf.drawing.Drawing`
    target: target :class:`~ezdxf.drawing.Drawing`

Attributes:
    source: source DXF document
    target: target DXF document
    used_layers: Set of used layer names as string, AutoCAD accepts layer
        names without a LAYER table entry.
    used_linetypes: Set of used linetype names as string, these linetypes
        require a TABLE entry or AutoCAD will crash.
    used_styles: Set of used text style names, these text styles require
        a TABLE entry or AutoCAD will crash.
    used_dimstyles: Set of used dimension style names, these dimension
        styles require a TABLE entry or AutoCAD will crash.

c                   Xl         X l        [        5       U l        [        5       U l        [        5       U l        [        5       U l        [        5       U l        [        5       U l        [        5       U l
        [        5       U l        [        5       U l        UR                  S   R                  R                   U l        UR$                  S   R                  R                   U l        g )NNormalGlobal)sourcetargetsetused_layersused_linetypesused_stylesused_shape_filesused_dimstylesused_arrowsdicthandle_mappinglistimported_insertsimported_blocks
plotstylesdxfhandle_default_plotstyle_handle	materials_default_material_handle)selfr:   r;   s      G/var/www/html/env/lib/python3.13/site-packages/ezdxf/addons/importer.py__init__Importer.__init__O   s    %%%(U(+%(U*-%(+%(U.2f 26 04v)/):):8)D)H)H)O)O&(.(8(8(B(F(F(M(M%    c                   U R                   R                  UR                  SS5      5        U R                  R                  UR                  SS5      5        UR	                  S5      (       a+  U R
                  R                  UR                  SS5      5        UR	                  S5      (       a,  U R                  R                  UR                  SS5      5        gg)	zRegister used resources.layer0linetypeBYLAYERstyleStandarddimstyleN)r=   addget_dxf_attribr>   is_supported_dxf_attribr?   rA   rN   entitys     rO   _add_used_resourcesImporter._add_used_resourcesd   s    V227C@A 5 5j) LM))'22  !6!6w
!KL))*55##F$9$9*j$QR 6rR   c                   U R                   R                  UR                  SS5      5        U R                  R                  UR                  SS5      5        U R                  R                  UR                  SS5      5        U R                  R                  UR                  SS5      5        U R                  R                  UR                  SS5      5        U R                  R                  UR                  S	S5      5        U R                  R                  UR                  S
S5      5        U R                  R                  UR                  SS5      5        g )NdimtxstyrY   dimltyperW   dimltex1dimltex2dimblk dimblk1dimblk2	dimldrblk)r?   r[   r\   r>   rB   )rN   rZ   s     rO   _add_dimstyle_resources Importer._add_dimstyle_resourcesm   s
   X44ZLM 7 7
I NO 7 7
I NO 7 7
I NOX44XrBCX44YCDX44YCDX44["EFrR   c                   UR                   R                  5       (       d  g UR                   R                  5       nU R                  R                  R                  U5      nUc  g UR                  R                  S:X  a0  U R                  R                  UR                  R                  5        g U R                  R                  UR                  R                  5        g )Nrh   )pattern_tagsis_complex_typeget_style_handler:   entitydbgetrI   namer@   r[   fontr?   )rN   rV   style_handlerX   s       rO   _add_linetype_resources Importer._add_linetype_resourcesw   s    $$4466,,==?$$((6=99>>R!!%%eiinn5  0rR   c                    [        U[        5      (       a  US:X  a  [        nOU4nU H  nU R                  USUS9  M     g)a`  Import DXF tables from the source document into the target document.

Args:
    table_names: iterable of tables names as strings, or a single table
        name as string or "*" for all supported tables
    replace: ``True`` to replace already existing table entries else
        ignore existing entries

Raises:
    TypeError: unsupported table type

*)entriesreplaceN)
isinstancestrIMPORT_TABLESimport_table)rN   table_namesr|   
table_names       rO   import_tablesImporter.import_tables   sD     k3''c!+*n%Jj#wG &rR   c           	     (   U[         ;  a  [        SU S35      e[        U R                  R                  U5      n[        U R
                  R                  U5      n[        U[        5      (       a  US:X  a
  S U 5       nOU4nU GHR  n UR                  U5      nUR                  R                  nXe;   ag  U(       aB  [        R                  SU S	U S
35        UR!                  UR                  R                  5        O[        R                  SU S	U S
35        M  US:X  a,  U R"                  R%                  UR'                  SS5      5        O/US:X  a  U R)                  U5        OUS:X  a  U R+                  U5        U R-                  U5      nUR/                  U5        UR                  R0                  U R2                  UR                  R0                  '   GMU     g! [        R                   a!    [        R                  SU SU S35         GM  f = f)a  
Import specific table entries from the source document into the
target document.

Args:
    name: valid table names are "layers", "linetypes" and "styles"
    entries: Iterable of table names as strings, or a single table name
        or "*" for all table entries
    replace: ``True`` to replace the already existing table entry else
        ignore existing entries

Raises:
    TypeError: unsupported table type

zTable "z" import not supported.rz   c              3  L   #    U  H  oR                   R                  v   M     g 7fN)rI   rt   ).0entrys     rO   	<genexpr>(Importer.import_table.<locals>.<genexpr>   s     D|e99>>|s   "$zRequired table entry "z" in table fz not found.z"Replacing already existing entry "z" of z table.z#Discarding already existing entry "r   rV   
Continuousr   r   N)r   	TypeErrorgetattrr:   tablesr;   r}   r~   rs   r	   DXFTableEntryErrorloggerwarningrI   rt   debugremover>   r[   r\   rl   rw   _duplicate_table_entry	add_entryrJ   rD   )	rN   rt   r{   r|   source_tabletarget_table
entry_nametable_entrynew_table_entrys	            rO   r   Importer.import_table   s   $ }$gdV+BCDDt{{1148t{{1148gs###~D|D"*!J*..z: %--J)LL<ZL I"V7, !''(<(<=LL=j\ J"V7, x##''..z<H $,,[9$,,[9 #99+FO""?3 ;J:M:M:T:TD 6 67M " ++ ,ZLTF K! " s   	G0HHc                \   U H  nU R                   R                  R                  U5      nU R                  R                  R	                  U5      nU(       a9  UR
                  R                  U R                  UR
                  R                  '   M  [        R                  SU S35        M     g)zImport shape file table entries from the source document into the
target document.
Shape file entries are stored in the styles table but without a name.

zRequired shape file entry "" not found.N)
r:   r   find_shxr;   get_shxrI   rJ   rD   r   r   )rN   fontsru   r   r   s        rO   import_shape_filesImporter.import_shape_files   s     D++,,55d;K"kk0088>O>M>Q>Q>X>X##KOO$:$:;!<TF,OP rR   c                   U R                   Ul        UR                  R                  S5      (       a  U R                  UR                  l        UR                  R                  S5      (       a  U R                  UR                  l        g g )Nplotstyle_handlematerial_handle)r;   docrI   hasattrrK   r   rM   r   r^   s     rO   _set_table_entry_dxf_attribs%Importer._set_table_entry_dxf_attribs   sb    [[
::011*.*H*HFJJ'::/00)-)F)FFJJ& 1rR   c                    [        U5      nU R                  U5        U R                  R                  R	                  U5        U$ r   )new_clean_entityr   r;   rr   r[   )rN   r   	new_entrys      rO   r   Importer._duplicate_table_entry   s:    $U+	))%0 	  +rR   Nc                  ^  U 4S jnUc  T R                   R                  5       nO0UR                  T R                   :w  a  [        R                  " S5      eUR                  5       nU[        ;  a#  [        R                  S[        U5       S35        gT R                  U5         [        [        [        U5      5      nU" U5        T R                   R                  R!                  U5        UR#                  U5         [%        T SUR'                  5       -   5      " U5        g! [        R                   a    [        R                  SU S35         gf = f! [(         a     gf = f)	a[  
Imports a single DXF `entity` into `target_layout` or the modelspace
of the target document, if `target_layout` is ``None``.

Args:
    entity: DXF entity to import
    target_layout: any layout (modelspace, paperspace or block) from
        the target document

Raises:
    DXFStructureError: `target_layout` is not a layout of target document

c                   > TR                   U l        U R                  R                  S5        U R                  R                  S5        U R                  R                  S5        g )Nr   r   visualstyle_handle)r;   r   rI   discard)erN   s    rO   set_dxf_attribs/Importer.import_entity.<locals>.set_dxf_attribs  sA    KKAEEEMM,-EEMM+,EEMM./rR   NzCTarget layout has to be a layout or block from the target document.z
Import of z not supportedzCopying for DXF type z not supported._import_)r;   
modelspacer   r	   DXFStructureErrordxftypeIMPORT_ENTITIESr   r   r~   r`   r   r   r   DXFTypeErrorrr   r[   
add_entityr   lowerAttributeError)rN   r_   target_layoutr   r   
new_entitys   `     rO   import_entityImporter.import_entity   s3   "	0   KK224M$++-))X  .."/)LL:c&k].AB  (	j*:6*BCJ
 	
#  ,  ,	D*w}}67
C !! 	LL0	IJ	  		s$   %D! =#E !-EE
E! E!c                v    U R                   R                  U5        UR                   H  n[        U5        M     g r   )rF   appendattribsremove_dependencies)rN   insertattribs      rO   _import_insertImporter._import_insert3  s,    $$V,nnF' %rR   c                @    UR                    H  n[        U5        M     g r   )verticesr   )rN   polylinevertexs      rO   _import_polylineImporter._import_polyline9  s    ''F' (rR   c                :    UR                   R                  S5        g )NassociativerI   r   )rN   hatchs     rO   _import_hatchImporter._import_hatch>  s    		-(rR   c                V   UR                   R                  S5        UR                   R                  S5        UR                   R                  S5        UR                   R                  S5        UR                   R                  S5        UR                   R                  S5        UR                   R                  S5        UR                   R                  S5        UR                   R                  S	5        UR                   R                  S
5        UR                   R                  S5        g )N
sun_handleclipping_boundary_handle
ucs_handleucs_base_handlebackground_handleshade_plot_handlevisual_style_handleref_vp_object_1ref_vp_object_2ref_vp_object_3ref_vp_object_4r   )rN   viewports     rO   _import_viewportImporter._import_viewportA  s    \*78\*./010123././././rR   c                   UR                   (       a^  UR                    HM  n[        U[        5      (       a$  U R                  UR                  R
                  SS9  U R                  U5        MO     g [        R                  S5        g )NFrenamez9The required geometry block for DIMENSION is not defined.)	virtual_block_contentr}   r   import_blockrI   rt   r`   r   error)rN   	dimensionr_   s      rO   _import_dimensionImporter._import_dimensionN  s`    **#99ff--%%fjjooe%D((0 :
 LLTUrR   c                8    U H  nU R                  X25        M     g)aX  Import all `entities` into `target_layout` or the modelspace of the
target document, if `target_layout` is ``None``.

Args:
    entities: Iterable of DXF entities
    target_layout: any layout (modelspace, paperspace or block) from
        the target document

Raises:
    DXFStructureError: `target_layout` is not a layout of target document

N)r   )rN   entitiesr   r_   s       rO   import_entitiesImporter.import_entitiesW  s    " Fv5 rR   c                T    U R                  U R                  R                  5       US9  g)aF  Import all entities from source modelspace into `target_layout` or
the modelspace of the target document, if `target_layout` is ``None``.

Args:
    target_layout: any layout (modelspace, paperspace or block) from
        the target document

Raises:
    DXFStructureError: `target_layout` is not a layout of target document

r   N)r   r:   r   )rN   r   s     rO   import_modelspaceImporter.import_modelspacek  s$     	T[[335]SrR   c                \  ^ ^ UU 4S jnSS jnTR                  5       S:X  a  T R                  R                  5       $ T R                  R                  R                  T5      nU" 5       nU" UR                  R                  5       5      nT R                  R                  R                  XVS9nU$ )a   Recreate source paperspace layout `name` in the target document.
The layout will be renamed if `name` already exist in the target
document. Returns target modelspace for layout name "Model".

Args:
    name: layout name as string

Raises:
    KeyError: if source layout `name` not exist

c                    > Tn TnSnU TR                   R                  ;   a/  U[        U5      -   n US-  nU TR                   R                  ;   a  M/  U $ )N   )r;   layoutsr~   )tname	base_namecountrt   rN   s      rO   get_target_name8Importer.recreate_source_layout.<locals>.get_target_name  sV    EIE4;;...!CJ.
 4;;... LrR   c                   ^  S
U 4S jjnU" S5        U" S5        U" S5        U" S5        U" S5        U" S5        U" S5        U" S	5        T $ )Nc                .   >  TU 	 g ! [          a     g f = fr   )KeyError)rt   
dxfattribss    rO   r   ?Importer.recreate_source_layout.<locals>.clear.<locals>.discard  s"    "4( s    
rJ   ownertaborderr   block_record_handleviewport_handler   base_ucs_handle)rt   r~    )r  r   s   ` rO   clear.Importer.recreate_source_layout.<locals>.clear  sT     HGJ'()*%&L!%&rR   model)r  )r  rC   returnrC   )	r   r;   r   r:   r   rs   
dxf_layoutr  new)rN   rt   r   r  source_layouttarget_namer  r   s   ``      rO   recreate_source_layoutImporter.recreate_source_layouty  s    		" ::<7";;))++++//5%'=33>>@A
++///SrR   c                    UR                  5       S:X  a  [        R                  " S5      eU R                  R                  R                  U5      nU R                  U5      nU R                  X#5        U$ )a  Import paperspace layout `name` into the target document.

Recreates the source paperspace layout in the target document, renames
the target paperspace if a paperspace with same `name` already exist
and imports all entities from the source paperspace into the target
paperspace.

Args:
    name: source paper space name as string

Returns: new created target paperspace :class:`Layout`

Raises:
    KeyError: source paperspace does not exist
    DXFTypeError: invalid modelspace import

r  z:Can not import modelspace, use method import_modelspace().)r   r	   r   r:   r   rs   r  r   )rN   rt   r  r   s       rO   import_paperspace_layout!Importer.import_paperspace_layout  sh    $ ::<7"$$L  ++//533D9]:rR   c                    U R                   R                  R                  5        H*  nUR                  5       S:w  d  M  U R	                  U5        M,     g)zImport all paperspace layouts and their content into the target
document.
Target layouts will be renamed if a layout with the same name already
exist. Layouts will be imported in original tab order.

r  N)r:   r   names_in_taborderr   r  )rN   rt   s     rO   import_paperspace_layouts"Importer.import_paperspace_layouts  s=     KK''99;Dzz|w&--d3 <rR   c                4    U H  nU R                  X2S9  M     g)aS  Import all BLOCK definitions from source document.

If a BLOCK already exist the BLOCK will be renamed if argument
`rename` is ``True``, otherwise the existing BLOCK in the target
document will be used instead of the BLOCK from the source document.
Required name resolving for imported BLOCK references (INSERT), will be
done in the :meth:`Importer.finalize` method.

Args:
    block_names: names of BLOCK definitions to import
    rename: rename BLOCK if a BLOCK with the same name already exist in
        target document

Raises:
    ValueError: BLOCK in source document not found (defined)

r   N)r   )rN   block_namesr   
block_names       rO   import_blocksImporter.import_blocks  s    $ &Jj8 &rR   c                x  ^^ SUU4S jjn U R                   T   $ ! [         a     Of = f U R                  R                  T   nO'! [        R
                   a    [        ST S35      ef = fU R                  R                  mTT;   a  USL a  TU R                   T'   T$ U" 5       nUR                  nUc   eTR                  UUR                  R                  UR                  R                  UR                  R                  UR                  R                  S.S9nU R                  XGS9  XPR                   T'   U$ )	a  Import one BLOCK definition from source document.

If the BLOCK already exist the BLOCK will be renamed if argument
`rename` is ``True``, otherwise the existing BLOCK in the target
document will be used instead of the BLOCK in the source document.
Required name resolving for imported block references (INSERT), will be
done in the :meth:`Importer.finalize` method.

To replace an existing BLOCK in the target document, just delete it
before importing data:
:code:`target.blocks.delete_block(block_name, safe=False)`

Args:
    block_name: name of BLOCK to import
    rename: rename BLOCK if a BLOCK with the same name already exist in
        target document

Returns: (renamed) BLOCK name

Raises:
    ValueError: BLOCK in source document not found (defined)

c                 R   > Sn TnUT;   a  T[        U 5      -   nU S-  n UT;   a  M  U$ )Nr   r   )r~   )numrt   r  target_blockss     rO   get_new_block_name1Importer.import_block.<locals>.get_new_block_name  s=    CD-'!CH,q -' KrR   zSource block "r   F)descriptionflags	xref_path)
base_pointr  r   )r  r~   )rG   r  r:   blocksr	   DXFKeyError
ValueErrorr;   blockr  rI   r*  r'  r(  r)  r   )	rN   r  r   r%  source_blocknew_block_namer.  target_blockr$  s	    `      @rO   r   Importer.import_block  sD   2	 		''
33 			H;;--j9L   	H~j\FGG	H **-'fo/9D  ,+-""   $((yy++$yy44"YY00 ) 
 	\F+9Z(s    
))A $A+c                    U R                   R                  S5        U R                    HK  n[        R                  " U5      (       a  U R                  R                  U5        M;  U R                  USS9  MM     g)zCreate or import required arrow blocks, used by the LEADER or the
DIMSTYLE entity, which are not imported automatically because they are
not used in an anonymous DIMENSION geometry BLOCK.

rh   Fr   N)rB   r   r
   is_acad_arrowr;   acquire_arrowr   )rN   
arrow_names     rO   _create_missing_arrowsImporter._create_missing_arrows%  sc     	  	
 **J##J//))*5!!*U!;	 +rR   c                &   [        U R                  5      (       aw  [        U R                  5      n/ U l        U H8  nU R                  UR                  R
                  5      nX2R                  l        M:     [        U R                  5      (       a  Mv  gg)zResolve BLOCK names of imported BLOCK reference entities (INSERT).

This is required for the case the name of the imported BLOCK collides
with an already existing BLOCK in the target document and the conflict
resolving method is "rename".

N)lenrF   rE   r   rI   rt   )rN   insertsr   r  s       rO   _resolve_insertsImporter._resolve_inserts4  sk     $''((4001G$&D!!!..vzz?
",

 "	 $''((rR   c                >   [        U R                  5      (       a  U R                  SU R                  5        [        U R                  5      (       a  U R                  SU R                  5        [        U R                  5      (       a  U R                  SU R                  5        [        U R
                  5      (       a  U R                  SU R
                  5        [        U R                  5      (       a  U R                  U R                  5        U R                  5         g)z\Import required table entries collected while importing entities
into the target document.

r   r   r   r   N)	r:  rA   r   r=   r>   r?   r@   r   update_complex_linetypesrN   s    rO   _import_required_table_entries'Importer._import_required_table_entriesD  s     t""##k4+>+>? t  h(8(89 t""##k4+>+>? t  h(8(89 t$$%%##D$9$9: 	%%'rR   c                    U R                    H:  n U R                  R                  R                  U5      nU R                  U5        M<     g ! [        R
                   a     MV  f = fr   )r>   r:   r   rs   r	   r   rw   )rN   
ltype_nameltypes      rO   (_add_required_complex_linetype_resources1Importer._add_required_complex_linetype_resourcesa  s[    --J--11*= ((/ . ++ s   %AA$#A$c                   U R                   R                  R                  S5      R                  R                  nU R                   R
                   Ht  nUR                  R                  5       (       d  M$  UR                  R                  5       nU R                  R                  X15      nUR                  R                  U5        Mv     g )NSTANDARD)r;   r   rs   rI   rJ   r   ro   rp   rq   rD   set_style_handle)rN   
std_handlerV   
old_handle
new_handles        rO   r?  !Importer.update_complex_linetypesi  s    [[''++J7;;BB
--H$$4466%22CCE
!0044ZL
%%66zB	 .rR   c                    U R                  5         U R                  5         U R                  5         U R                  5         g)zFinalize the import by importing required table entries and BLOCK
definitions, without finalization the target document is maybe invalid
for AutoCAD. Call the :meth:`~Importer.finalize()` method as last step
of the import process.

N)r<  rF  rA  r7  r@  s    rO   finalizeImporter.finalizeq  s4     	557++-##%rR   )rM   rK   rD   rG   rF   r:   r;   rB   rA   r=   r>   r@   r?   )r:   r   r;   r   )r_   r   r  None)rZ   r   r  rR  )rV   r   r  rR  )rz   F)r   Union[str, Iterable[str]]r  rR  )rt   r~   r{   rS  r  rR  )r   zset[str]r  rR  )r   r   r  r   r   )r_   r   r   Optional[BaseLayout]r  rR  )r   r   )r   r   )r   r   )r   r   )r   r   )r   zIterable[DXFEntity]r   rT  r  rR  )r   rT  r  rR  )rt   r~   r  r   )r  rR  F)r  zIterable[str]r  rR  )T)r  r~   r  r~   )"__name__
__module____qualname____firstlineno____doc__rP   r`   rl   rw   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r   r7  r<  rA  rF  r?  rP  __static_attributes__r
  rR   rO   r5   r5   8   s    ,N*SG1 EJH4H	H0 LQBUBU";BU	BUHQ G HL220D2	2h((
)0V /36%6 ,6 
	6(T/b6	49*>@<- (:0C
&rR   r5   c                B    U R                  5       nSUl        [        X!S9$ )zqCopy entity and remove all external dependencies.

Args:
    entity: DXF entity
    keep_xdata: keep xdata flag

N)
keep_xdata)copyr   r   )r_   r]  r   s      rO   r   r   ~  s!     JJNzAArR   c                L    SU l         SU l        SU l        U(       d  SU l        U $ )zaRemove all external dependencies.

Args:
    entity: DXF entity
    keep_xdata: keep xdata flag

N)appdatareactorsextension_dictxdata)r_   r]  s     rO   r   r     s)     FNFO FMrR   rU  )r_   r   r]  boolr  r   )#
__future__r   typingr   r   r   r   r   loggingezdxf.lldxfr	   ezdxf.render.arrowsr
   ezdxf.entitiesr   r   r   r   r   r   r   r   r   ezdxf.documentr   ezdxf.layoutsr   r   	getLoggerr   r   r   r5   r   r   r
  rR   rO   <module>rn     sg    # A A   &
 
 
 &0			7	#>8C	& C	&L
BrR   