
    h~@                       S SK Jr  S SKJrJrJrJrJr  S SKJ	r	J
r
Jr  S SKJr  S SKJrJrJrJrJr  S SKJr  S SKJr  S SKJrJr  S S	KJr  \(       a  S S
KJrJrJr  S SK J!r!  1 Skr" " S S\5      r# " S S\#5      r$ " S S\#5      r%g)    )annotations)TYPE_CHECKINGIteratorUnionIterableOptional)factoryis_graphic_entitySortEntsTable)InsertUnits)DXFKeyErrorDXFValueErrorDXFStructureErrorLATEST_DXF_VERSIONDXFTypeError)EntityQuery)groupby)EntityDBEntitySpace)CreatorInterface)
DXFGraphicBlockRecordExtensionDict)KeyFunc>   ARCLINEMESHTEXTHATCHMTEXTPOINTSHAPESOLIDTRACE3DFACEATTDEFATTRIBCIRCLESPLINEELLIPSEPOLYLINE
LWPOLYLINEc                  x    \ rS rSr\" 5       r\SS j5       rSS jrSS jr	S r
SSS jjrSSS jjrS	 rS
 rSrg)_AbstractLayout.   c                .    U R                   R                  $ )z/Returns drawing entity database. (internal API))docentitydbselfs    D/var/www/html/env/lib/python3.13/site-packages/ezdxf/layouts/base.pyr2   _AbstractLayout.entitydb1   s     xx       c                ,    [        U R                  5      $ )z.Returns count of entities owned by the layout.)lenentity_spacer3   s    r5   __len___AbstractLayout.__len__6   s    4$$%%r7   c                ,    [        U R                  5      $ )z8Returns iterable of all drawing entities in this layout.)iterr:   r3   s    r5   __iter___AbstractLayout.__iter__:   s    D%%&&r7   c                     U R                   U   $ )aS  Get entity at `index`.

The underlying data structure for storing entities is organized like a
standard Python list, therefore `index` can be any valid list indexing
or slicing term, like a single index ``layout[-1]`` to get the last
entity, or an index slice ``layout[:10]`` to get the first 10 or less
entities as ``list[DXFGraphic]``.

r:   )r4   indexs     r5   __getitem___AbstractLayout.__getitem__>   s       ''r7   c                ,    [        [        U 5      U5      $ )z=Get all DXF entities matching the :ref:`entity query string`.)r   r>   )r4   querys     r5   rG   _AbstractLayout.queryJ   s    4:u--r7   Nc                ,    [        [        U 5      X5      $ )a  
Returns a ``dict`` of entity lists, where entities are grouped by a
`dxfattrib` or a `key` function.

Args:
    dxfattrib: grouping by DXF attribute like ``'layer'``
    key: key function, which accepts a :class:`DXFGraphic` entity as
        argument and returns the grouping key of an entity or ``None``
        to ignore the entity. Reason for ignoring: a queried DXF
        attribute is not supported by entity.

)r   r>   )r4   	dxfattribkeys      r5   r   _AbstractLayout.groupbyN   s     tDz922r7   c                    g N r3   s    r5   destroy_AbstractLayout.destroy]   s    r7   c                8    U R                   R                  5         g)z;Remove all destroyed entities from the layout entity space.N)r:   purger3   s    r5   rS   _AbstractLayout.purge`   s    !r7   rO   )returnr   )rU   int)rU   zIterator[DXFGraphic])*)rG   strrU   r   ) N)rJ   rX   rK   zOptional[KeyFunc]rU   dict)__name__
__module____qualname____firstlineno__r   r:   propertyr2   r;   r?   rD   rG   r   rP   rS   __static_attributes__rO   r7   r5   r.   r.   .   s>    =L! !&'
(.3"r7   r.   c                    ^  \ rS rSrSU 4S jjr\S 5       r\SS j5       r\S 5       r\SS j5       r	\SS j5       r
\SS j5       r\SS	 j5       r\SS
 j5       r\SS j5       r\R                  SS j5       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S"S jrS!S$S jjrS%S jrS&S jrS'S(S jjrSrU =r$ ))
BaseLayoute   c                t   > UR                   nUc   e[        TU ]	  U5        UR                  U l        Xl        g rN   )r1   super__init__r:   block_record)r4   rg   r1   	__class__s      r5   rf   BaseLayout.__init__f   s9    (55)5r7   c                B    U R                   R                  R                  $ )z+Returns block record handle. (internal API)rg   dxfhandler3   s    r5   block_record_handleBaseLayout.block_record_handlen   s       $$+++r7   c                B    U R                   R                  R                  $ )zReturns the layout key as hex string.

The layout key is the handle of the associated BLOCK_RECORD entry in the
BLOCK_RECORDS table.

(internal API)
rk   r3   s    r5   
layout_keyBaseLayout.layout_keys   s       $$+++r7   c                .    U R                   R                  $ )z``False`` if layout is deleted.)rg   is_aliver3   s    r5   rt   BaseLayout.is_alive~   s       )))r7   c                f    U R                   R                  (       a  U R                   R                  $ g)z``True`` if is active layout.F)rg   rt   is_active_paperspacer3   s    r5   rw   BaseLayout.is_active_paperspace   s(     %%$$999r7   c                .    U R                   R                  $ )z-``True`` if is any kind of paperspace layout.)rg   is_any_paperspacer3   s    r5   rz   BaseLayout.is_any_paperspace   s       222r7   c                .    U R                   R                  $ )z!``True`` if is modelspace layout.)rg   is_modelspacer3   s    r5   r}   BaseLayout.is_modelspace          ...r7   c                .    U R                   R                  $ )z;``True`` if is any kind of modelspace or paperspace layout.)rg   is_any_layoutr3   s    r5   r   BaseLayout.is_any_layout   r   r7   c                .    U R                   R                  $ )z^``True`` if not any kind of modelspace or paperspace layout, just a
regular block definition.
)rg   is_block_layoutr3   s    r5   r   BaseLayout.is_block_layout   s    
   000r7   c                B    U R                   R                  R                  $ )zOGet/Set layout/block drawing units as enum, see also :ref:`set
drawing units`.
rg   rl   unitsr3   s    r5   r   BaseLayout.units   s       $$***r7   c                8    XR                   R                  l        g)z'Set layout/block drawing units as enum.Nr   )r4   values     r5   r   r      s     ',#r7   c                |    U R                   nUR                  (       a  UR                  5       $ UR                  5       $ )zMReturns the associated extension dictionary, creates a new one if
necessary.
)rg   has_extension_dictget_extension_dictnew_extension_dict)r4   rg   s     r5   r   BaseLayout.get_extension_dict   s6     ((**22442244r7   c                   U R                   nUR                  R                  c  U(       a  [        R                  " X5        UR                  R                  nUb  X0R                   R
                  ;  a  [        S5      e[        U5      (       d  [        S[        U5       35      eU R                  R                  U5        g)a  Add an existing :class:`DXFGraphic` entity to a layout, but be sure
to unlink (:meth:`~BaseLayout.unlink_entity`) `entity` from the previous
owner layout.  Adding entities from a different DXF drawing is not
supported.

.. warning:: 

    This is a low-level tool - use it with caution and make sure you understand 
    what you are doing! If used improperly, the DXF document may be damaged.

Nz>Adding entities from a different DXF drawing is not supported.zinvalid entity )r1   rl   rm   r	   bindr2   r   r
   r   rX   rg   
add_entity)r4   entityr1   rm   s       r5   r   BaseLayout.add_entity   s     hh::$LL%"">V88+<+<<#P  !((V>??$$V,r7   c                X   UR                   nUR                  5       nU[        ;  a  [        SU 35      eX0R                   L a  [	        S5      eUb.  U(       a  UR                  5       nO[        R                  " U5        UR                  U R                   5        U R                  U5        g)a  Add a foreign DXF entity to a layout, this foreign entity could be
from another DXF document or an entity without an assigned DXF document.
The intention of this method is to add **simple** entities from another
DXF document or from a DXF iterator, for more complex operations use the
:mod:`~ezdxf.addons.importer` add-on. Especially objects with BLOCK
section (INSERT, DIMENSION, MLEADER) or OBJECTS section dependencies
(IMAGE, UNDERLAY) can not be supported by this simple method.

Not all DXF types are supported and every dependency or resource
reference from another DXF document will be removed except attribute
layer will be preserved but only with default attributes like
color ``7`` and linetype ``CONTINUOUS`` because the layer attribute
doesn't need a layer table entry.

If the entity is part of another DXF document, it will be unlinked from
this document and its entity database if argument `copy` is ``False``,
else the entity will be copied. Unassigned entities like from DXF
iterators will just be added.

Supported DXF types:

    - POINT
    - LINE
    - CIRCLE
    - ARC
    - ELLIPSE
    - LWPOLYLINE
    - SPLINE
    - POLYLINE
    - 3DFACE
    - SOLID
    - TRACE
    - SHAPE
    - MESH
    - ATTRIB
    - ATTDEF
    - TEXT
    - MTEXT
    - HATCH

Args:
    entity: DXF entity to copy or move
    copy: if ``True`` copy entity from other document else unlink from
        other document

Raises:
    CopyNotSupported: copying of `entity` i not supported
zunsupported DXF type: zentity from same DXF documentN)
r1   dxftypeSUPPORTED_FOREIGN_ENTITY_TYPESr   r   copyr	   unbindremove_dependenciesr   )r4   r   r   foreign_docr   s        r5   add_foreign_entityBaseLayout.add_foreign_entity   s    b jj.."88!7yABB((" ?@@" v&""488,r7   c                :    U R                   R                  U5        g)zUnlink `entity` from layout but does not delete entity from the
entity database, this removes `entity` just from the layout entity space.
N)rg   unlink_entityr4   r   s     r5   r   BaseLayout.unlink_entity       	''/r7   c                :    U R                   R                  U5        g)z^Delete `entity` from layout entity space and the entity database,
this destroys the `entity`.
N)rg   delete_entityr   s     r5   r   BaseLayout.delete_entity  r   r7   c                J    [        U 5       H  nU R                  U5        M     g)zjDelete all entities from this layout and from entity database,
this destroys all entities in this layout.
N)listr   r   s     r5   delete_all_entitiesBaseLayout.delete_all_entities"  s      4jFv& !r7   c                    UR                   UR                   :w  a  [        S5      e U R                  U5        UR                  U5        g! [         a    [        S5      ef = f)zMove entity to another layout.

Args:
    entity: DXF entity to move
    layout: any layout (modelspace, paperspace, block) from
        **same** drawing

z7Moving between different DXF drawings is not supported.zLayout does not contain entity.N)r1   r   r   r   
ValueErrorr   )r4   r   layouts      r5   move_to_layoutBaseLayout.move_to_layout+  sf     ::##I 	&v& f%  	C ABB	Cs   A
 
A c                    U R                   R                  R                  U R                  R                  R
                  5        g)z+Delete all linked resources. (internal API)N)r1   block_recordsremoverg   rl   namer3   s    r5   rP   BaseLayout.destroy?  s.     	%%d&7&7&;&;&@&@Ar7   c                    U R                  5       n US   nU$ ! [         aU    U(       aB  U R                  R                  R	                  SUR
                  U R                  S.S9nX2S'    U$ [        S5      ef = f)zGet/Create the SORTENTSTABLE object associated to the layout.

Args:
    create: new table if table do not exist and `create` is ``True``

Raises:
    DXFValueError: if table not exist and `create` is ``False``

(internal API)
ACAD_SORTENTSSORTENTSTABLE)ownerrn   
dxfattribsz8Extension dictionary entry ACAD_SORTENTS does not exist.)r   r   r1   objects
new_entityrm   rq   r   )r4   createxdictsortents_tables       r5   get_sortents_tableBaseLayout.get_sortents_tableE  s     '')	"?3N   	!%!1!1!<!<#!&/3  "= " *8o&
  $N 	s    AA8,A8c                    U R                  5       n[        U[        5      (       a  UR                  5       nUR	                  U5        g)al  If the header variable $SORTENTS `Regen` flag (bit-code value 16)
is set, AutoCAD regenerates entities in ascending handles order.

To change redraw order associate a different sort-handle to entities,
this redefines the order in which the entities are regenerated.
The `handles` argument can be a dict of entity_handle and sort_handle
as (k, v) pairs, or an iterable of (entity_handle, sort_handle) tuples.

The sort-handle doesn't have to be unique, some or all entities can
share the same sort-handle and a sort-handle can be an existing handle.

The "0" handle can be used, but this sort-handle will be drawn as
latest (on top of all other entities) and not as first as expected.

Args:
    handles: iterable or dict of handle associations; an iterable
        of 2-tuples (entity_handle, sort_handle) or a dict (k, v)
        association as (entity_handle, sort_handle)

N)r   
isinstancerZ   itemsset_handles)r4   handlessortentss      r5   set_redraw_orderBaseLayout.set_redraw_orderc  s8    * **,gt$$mmoGW%r7   c                    U R                   R                  (       a  U R                  5       nO
[        5       $  US   n[        U5      $ ! [         a    [        5       s $ f = f)zReturns iterable for all existing table entries as (entity_handle,
sort_handle) pairs, see also :meth:`~BaseLayout.set_redraw_order`.

r   )rg   r   r   tupler   r>   )r4   r   r   s      r5   get_redraw_orderBaseLayout.get_redraw_order}  s\    
 //++-E7N	"?3N N##  	7N	s   A AAc                    SSK Jn  U R                  5       nU(       a  UR                  U R                  U5      $ UR                  U R                  U5      $ )zoYields all entities from layout in ascending redraw order or
descending redraw order if `reverse` is ``True``.
r   )reorder)ezdxfr   r   
descendingr:   	ascending)r4   reverser   redraw_orders       r5   entities_in_redraw_order#BaseLayout.entities_in_redraw_order  sJ     	",,.%%d&7&7FF  !2!2LAAr7   )rg   r:   )rg   r   rU   rX   )rU   bool)rU   r   )r   r   rU   None)rU   r   r   r   rU   r   )TrU   r   )r   r   r   rb   rU   r   )r   r   rU   r   )r   z&Union[dict, Iterable[tuple[str, str]]]rU   r   )rU   zIterable[tuple[str, str]])F)rU   zIterable[DXFGraphic])r[   r\   r]   r^   rf   r_   rn   rq   rt   rw   rz   r}   r   r   r   setterr   r   r   r   r   r   r   rP   r   r   r   r   r`   __classcell__rh   s   @r5   rb   rb   e   s   6 , , , , * *   3 3 / / / / 1 1 + + \\, ,5-4A F00'&(B<&4$ 	B 	Br7   rb   c                     ^  \ rS rSrSrU 4S jr\SS j5       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U =r$ )VirtualLayouti  aP  Helper class to disassemble complex entities into basic DXF
entities by rendering into a virtual layout.

All entities do not have an assigned DXF document and therefore
are not stored in any entity database and can not be added to another
layout by :meth:`add_entity`.

Deleting entities from this layout does not destroy the entity!

c                B   > [         TU ]  S 5        [        5       U l        g rN   )re   rf   r   r:   )r4   rh   s    r5   rf   VirtualLayout.__init__  s    'Mr7   c                    [         $ rN   )r   r3   s    r5   
dxfversionVirtualLayout.dxfversion  s    !!r7   c                :    U R                   R                  U5        g rN   )r:   addr   s     r5   r   VirtualLayout.add_entity  s    f%r7   c                d    [         R                  " XS9nU R                  R                  U5        U$ )Nr   )r	   newr:   r   )r4   type_r   r   s       r5   r   VirtualLayout.new_entity  s)    U:f%r7   c                :    U R                   R                  U5        g rN   r:   r   r   s     r5   r   VirtualLayout.unlink_entity        (r7   c                :    U R                   R                  U5        g rN   r   r   s     r5   r   VirtualLayout.delete_entity  r   r7   c                8    U R                   R                  5         g rN   )r:   clearr3   s    r5   r   !VirtualLayout.delete_all_entities  s    !r7   c                    UR                   nUR                  nU R                   H<  n UR                  5       nX%l         UR                  U5        UR                  U5        M>     g! [         a     MN  f = f)z,Copy all entities to a real document layout.N)r1   r2   r:   r   r   r   r   )r4   r   r1   r2   r   clones         r5   copy_all_to_layout VirtualLayout.copy_all_to_layout  si    jj<<''F ILLe$ (   s   A&&
A43A4c                    UR                   nUR                  nU R                   H+  nX$l         UR                  U5        UR	                  U5        M-     U R                  5         g)z,Move all entities to a real document layout.N)r1   r2   r:   r   r   r   )r4   r   r1   r2   r   s        r5   move_all_to_layout VirtualLayout.move_all_to_layout  sQ    jj<<''FJLL f% ( 	  "r7   rB   r   r   )r   rX   r   rZ   rU   r   r   )r   rb   rU   r   )r[   r\   r]   r^   __doc__rf   r_   r   r   r   r   r   r   r   r   r`   r   r   s   @r5   r   r     sI    	* " "&
))"%# #r7   r   N)&
__future__r   typingr   r   r   r   r   ezdxf.entitiesr	   r
   r   ezdxf.enumsr   ezdxf.lldxf.constr   r   r   r   r   ezdxf.queryr   ezdxf.groupbyr   ezdxf.entitydbr   r   ezdxf.graphicsfactoryr   r   r   r   ezdxf.eztypesr   r   r.   rb   r   rO   r7   r5   <module>r     sp    # E E D D #  $ ! 0 2EE%" ,4"& 4"nqB qBh	:#O :#r7   