
    h>                    H   S SK Jr  S SKJrJrJrJrJrJr  S SK	J
r
  S SKrS SKJr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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#  \(       a&  S SKJ$r$  S SK%J&r&  S SK'J(r(J)r)  S SK*J+r+  S SK,J-r-  S SK.J/r/  SS/r0\Rb                  " S5      r2\" S\" SSS9\" SS\Rf                  \S9\" SS\Rf                  \S9S.5      r4\" \45      r5Sr6\ " S  S\5      5       r7 S'       S(S! jjr8S)S" jr9S*S# jr:S+S$ jr; " S% S\ \7   5      r<S,S& jr=g)-    )annotations)TYPE_CHECKINGIterableIteratorcastUnionOptional)contextmanagerN)	validatorconst)DXFAttrDXFAttributesDefSubclassRETURN_DEFAULTgroup_code_mapping)
AuditError   )
base_classSubclassProcessor	DXFEntity)	DXFObject)register_entity)ObjectCollection)default_copyCopyNotSupported)Auditor)Drawing)DXFNamespace
Dictionary)EntityDB)Layouts)AbstractTagWriterDXFGroupGroupCollectionezdxf	AcDbGroupi,   )defaultF   )r(   r   fixerG   descriptionunnamed
selectableiT  c                  :  ^  \ rS rSrSrSr\" \\5      r	SU 4S jjr
\4S jr S   SU 4S jjjrS rSS jrSU 4S	 jjrS S
 jrS!S jrS"S jrS rS#S jrS$S jrS%U 4S j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+S jr!Sr"U =r#$ ),r#   D   zGroups are not allowed in block definitions, and each entity can only
reside in one group, so cloning of groups creates also new entities.

GROUPc                N   > [         TU ]  5         [        5       U l        / U l        g N)super__init__set_handles_data)self	__class__s    J/var/www/html/env/lib/python3.13/site-packages/ezdxf/entities/dxfgroups.pyr6   DXFGroup.__init__N   s    "%%&(
    c                    [        S5      e)NzCopying of GROUP not supported.)r   )r:   copy_strategys     r<   copyDXFGroup.copyS   s    @AAr>   c                   > [         TU ]  U5      nU(       a'  UR                  U[        SSS9nU R	                  U5        U$ )Nr   F)log)r5   load_dxf_attribsfast_load_dxfattribsacdb_group_group_codes
load_group)r:   	processordxftagsr;   s       r<   rE   DXFGroup.load_dxf_attribsV   sI     g&y111+QE 2 D OOD!
r>   c                h    U H,  u  p#U[         :X  d  M  U R                  R                  U5        M.     g r4   )GROUP_ITEM_CODEr8   add)r:   rK   codevalues       r<   rH   DXFGroup.load_groupa   s*    KD& !!%(	  r>   c                    U R                   c   eU R                  U R                   5        [        U R                  5      (       d  [        R
                  " S5      eg)NWAll entities have to be in the same layout and are not allowed to be in a block layout.T)docpurgeall_entities_on_same_layoutr9   r   DXFStructureError)r:   	tagwriters     r<   preprocess_exportDXFGroup.preprocess_exporth   sN    xx###

488*4::66)),  r>   c                   > [         TU ]  U5        UR                  [        R                  [
        R                  5        U R                  R                  U/ SQ5        U R                  U5        g)z(Export entity specific data as DXF tags.r,   N)
r5   export_entity
write_tag2r   SUBCLASS_MARKER
acdb_groupnamerJ   export_dxf_attribsexport_group)r:   rY   r;   s     r<   r]   DXFGroup.export_entityt   sM    i(U22JOOD##I/WX)$r>   c                ~    U R                    H-  nUR                  [        UR                  R                  5        M/     g r4   )r9   r^   rN   rJ   handle)r:   rY   entitys      r<   rc   DXFGroup.export_group{   s*    jjF  &**2C2CD !r>   c                (    S U R                    5       $ )zzIterate over all DXF entities in :class:`DXFGroup` as instances of
:class:`DXFGraphic` or inherited (LINE, CIRCLE, ...).

c              3  J   #    U  H  oR                   (       d  M  Uv   M     g 7fr4   )is_alive).0es     r<   	<genexpr>$DXFGroup.__iter__.<locals>.<genexpr>   s     4:a:s   #	#r9   r:   s    r<   __iter__DXFGroup.__iter__   s    
 54::44r>   c                ,    [        U R                  5      $ )z7Returns the count of DXF entities in :class:`DXFGroup`.)lenr9   rq   s    r<   __len__DXFGroup.__len__   s    4::r>   c                     U R                   U   $ )z9Returns entities by standard Python indexing and slicing.rp   )r:   items     r<   __getitem__DXFGroup.__getitem__   s    zz$r>   c                    [        U[        5      (       a  UOUR                  R                  nU[	        U R                  5       5      ;   $ )zReturns ``True`` if item is in :class:`DXFGroup`. `item` has to be
a handle string or an object of type :class:`DXFEntity` or inherited.

)
isinstancestrrJ   rf   r7   handles)r:   ry   rf   s      r<   __contains__DXFGroup.__contains__   s5    
 $D#..DHHOOT\\^,,,r>   c                    S U  5       $ )z=Iterable of handles of all DXF entities in :class:`DXFGroup`.c              3  L   #    U  H  oR                   R                  v   M     g 7fr4   )rJ   rf   rl   rg   s     r<   rn   #DXFGroup.handles.<locals>.<genexpr>   s     5f

!!   "$ rq   s    r<   r   DXFGroup.handles   s    555r>   c                   >^ ^ [         TT ]  U5        UR                  R                  mU 4S jnUU 4S jn[	        U" 5       5      T l        T ?U$ )Nc                    > [        T5      n [        TR                  TR                  U 5      n[	        U5      (       d*  TR                  5         [        R                  SU  S35        g UTl        g )NCleared z&, had entities from different layouts.)r~   filter_invalid_entitiesr9   rU   rW   clearloggerdebug)ra   entitiesr:   s     r<   set_group_entities3DXFGroup.post_load_hook.<locals>.set_group_entities   sS    t9D.tzz488TJH.x88

xv-STU%
r>   c               3     >#    TR                    H+  n T" U 5      nU(       d  M  UR                  (       d  M'  Uv   M-     g 7fr4   )r8   rk   )rf   rg   db_getr:   s     r<   r   )DXFGroup.post_load_hook.<locals>.entities   s/     --6fooo L (s   A A 	A )r5   post_load_hookentitydbgetlistr9   r8   )r:   rU   r   r   r   r;   s   `   @r<   r   DXFGroup.post_load_hook   sD    s#!!	&	! (*%
M!!r>   c              #  L   #    [        U 5      nUv   U R                  U5        g7f)a  Context manager which yields all the group entities as
standard Python list::

    with group.edit_data() as data:
       # add new entities to a group
       data.append(modelspace.add_line((0, 0), (3, 0)))
       # remove last entity from a group
       data.pop()

N)r   set_data)r:   datas     r<   	edit_dataDXFGroup.edit_data   s!      Dz
dr   c                    U R                   c   e[        U5      n[        XR                   [        U 5      5      n[	        U5      [	        U5      :w  a  [
        R                  " S5      e[        U5      (       d  [
        R                  " S5      eU$ )Nzinvalid entities foundrT   )rU   r   r   r~   ru   r   rX   rW   r:   r   valid_entitiess      r<   _validate_entitiesDXFGroup._validate_entities   s}    xx###>088SYO~#h-/))*BCC*>::)),  r>   c                t    U R                  U5      nU R                  5         U R                  U5        X l        g)zSet `entities` as new group content, entities should be an iterable of
:class:`DXFGraphic` (LINE, CIRCLE, ...).

Raises:
    DXFValueError: not all entities are located on the same layout (modelspace
        or any paperspace layout but not block)

N)r   r   _add_group_reactorr9   r   s      r<   r   DXFGroup.set_data   s0     00:

/#
r>   c                   U R                  U5      n[        U R                  5       5      nU Vs/ s H   oDR                  R                  U;  d  M  UPM"     nnU R                  U5        U R                  R                  U5        gs  snf )zAdd `entities` to :class:`DXFGroup`, entities should be an iterable of
:class:`DXFGraphic` (LINE, CIRCLE, ...).

Raises:
    DXFValueError: not all entities are located on the same layout (modelspace
        or any paperspace layout but not block)

N)r   r7   r   rJ   rf   r   r9   extend)r:   r   r   r   rm   s        r<   r   DXFGroup.extend   sk     00:dlln%%3S^uu||77R!^S/

.) Ts   BBc                H    U R                  U R                  5        / U l        g)zlRemove all entities from :class:`DXFGroup`, does not delete any
drawing entities referenced by this group.

N)_remove_group_reactorr9   rq   s    r<   r   DXFGroup.clear   s     	""4::.
r>   c                d    U R                   R                  nU H  nUR                  U5        M     g r4   )rJ   rf   append_reactor_handler:   r   group_handlerg   s       r<   r   DXFGroup._add_group_reactor   s'    xxF((6 r>   c                d    U R                   R                  nU H  nUR                  U5        M     g r4   )rJ   rf   discard_reactor_handler   s       r<   r   DXFGroup._remove_group_reactor   s'    xxF)),7 r>   c           	        [        U 5      nUR                  c   eU R                  UR                  5        U[        U 5      -
  nUS:  a-  UR                  [        R
                  SU S[        U 5       3S9  [        U R                  5      (       d;  UR                  [        R                  S[        U 5       S3S9  U R                  5         U R                  R                  nU(       d  gU R                   HW  nUR                  b  XER                  ;  d  M!  UR                  [        R                  SU S	U S
3S9  UR                  U5        MY     g)zRemove invalid entities from :class:`DXFGroup`.

Invalid entities are:

- deleted entities
- all entities which do not reside in model- or paper space
- all entities if they do not reside in the same layout

Nr   zRemoved z invalid entities from rP   messager   z2, not all entities are located in the same layout.zEntity z in group #z* does not have group as persistent reactor)ru   rU   rV   fixed_errorr   INVALID_GROUP_ENTITIESr~   rW   r9   #GROUP_ENTITIES_IN_DIFFERENT_LAYOUTSr   rJ   rf   reactorsMISSING_PERSISTENT_REACTORr   )r:   auditorentity_countremoved_entity_countr   rg   s         r<   auditDXFGroup.audit   s?    4y{{&&&

7;;+c$i7!#66"#7"88OPSTXPY{[    +4::66CC"3t9+ .# $   
 JJLxxjjF&,oo*M###>>%fX[ G2 3 $ 
 ,,\: !r>   c                J    [        U R                  U[        U 5      S9U l        g)zRemove invalid group entities.)r   rU   
group_nameN)r   r9   r~   )r:   rU   s     r<   rV   DXFGroup.purge(  s    ,ZZSSY

r>   )r9   r8   )returnNoner4   )rI   zOptional[SubclassProcessor]r   r   )rY   r"   r   bool)rY   r"   r   r   )rY   r"   )r   zIterator[DXFEntity])r   int)ry   zUnion[str, DXFEntity]r   r   )r   zIterable[str])rU   z	'Drawing')r   list[DXFEntity])r   Iterable[DXFEntity]r   r   )r   r   r   r   )r   r   r   r   r   r   r   r   )rU   r   r   r   )$__name__
__module____qualname____firstlineno____doc__DXFTYPEr   r   r`   
DXFATTRIBSr6   r   rA   rE   rH   rZ   r]   rc   rr   rv   rz   r   r   r   r
   r   r   r   r   r   r   r   r   rV   __static_attributes____classcell__r;   s   @r<   r#   r#   D   s    
 Gz:6J)
 ". B 8<	4			 	)
%E5 -6"2  $*7
8
&;P
 
r>   c                   Uc   eUR                   n[        UR                  5      n/ nU  H  nUR                  (       a8  [	        UR
                  R                  X45      (       a  UR                  U5        ML  U(       d  MU  UR                  (       a&  [        R                  [        U5       SU S35        M  [        R                  SU 35        M     U$ )Nz in z has an invalid owner.zRemoved deleted entity in )r   valid_layout_handleslayoutsrk   _has_valid_ownerrJ   ownerappendr   r   r~   )r   rU   r   dbvalid_owner_handlesr   rg   s          r<   r   r   /  s    
 ??	B.s{{;&(N??/JJb 
  
 !!&)ZF}D<RST9*FG  r>   c                    U c  gU(       a  X;  a  gUR                  U 5      nUb  UR                  (       d  gUR                  R                  S:g  $ )NF0)r   rk   rJ   layout)r   r   r   r   s       r<   r   r   E  sG    }u?VVE]F~V__
 ::##r>   c                B    [        S U  5       5      n[        U5      S:  $ )z_Check if all entities are on the same layout (model space or any paper
layout but not block).

c              3  L   #    U  H  oR                   R                  v   M     g 7fr4   )rJ   r   r   s     r<   rn   .all_entities_on_same_layout.<locals>.<genexpr>\  s     9f!!r      )r7   ru   )r   ownerss     r<   rW   rW   W  s"    
 999Fv;?r>   c                &    [        S U  5       5      $ )z-Returns valid layout keys for group entities.c              3  ^   #    U  H#  oR                   (       d  M  UR                  v   M%     g 7fr4   )is_any_layout
layout_key)rl   r   s     r<   rn   'valid_layout_handles.<locals>.<genexpr>c  s     OwV:N:N v  ws   --)r7   )r   s    r<   r   r   a  s    OwOOOr>   c                     ^  \ rS rSrS
U 4S jjrSS jrSS jrSS jr   S       SS jjrSU 4S jjr	SS jr
S	rU =r$ )r$   if  c                2   > [         TU ]  USSS9  SU l        g )N
ACAD_GROUPr2   )	dict_nameobject_typer   )r5   r6   _next_unnamed_number)r:   rU   r;   s     r<   r6   GroupCollection.__init__g  s    'J$%!r>   c              #  *   #    U  H	  u  pUv   M     g7f)z Iterable of all existing groups.Nr   )r:   ra   groups      r<   groupsGroupCollection.groupsk  s     KDK  s   c                ^    U R                  5       nX;   a  U R                  5       nX;   a  M  U$ r4   )
_next_name)r:   ra   s     r<   	next_nameGroupCollection.next_namep  s+     l??$D lr>   c                J    U =R                   S-  sl         SU R                    3$ )Nr   z*Ar   rq   s    r<   r   GroupCollection._next_namev  s'    !!Q&!D--.//r>   c                    Ub  X;   a  [         R                  " SU S35      eUc  U R                  5       nSnOSnUU[        [	        U5      5      S.n[        [        U R                  X5      5      $ )a(  Creates a new group. If `name` is ``None`` an unnamed group is
created, which has an automatically generated name like "\*Annnn".
Group names are case-insensitive.

Args:
    name: group name as string
    description: group description as string
    selectable: group is selectable if ``True``

zGROUP 'z' already exists.r   r   r,   )r   DXFValueErrorr   r   r   r   r#   _new)r:   ra   r-   r/   r.   
dxfattribss         r<   newGroupCollection.newz  sx      %%v5F&GHH<>>#DGG 'd:./


 Hdii9::r>   c                2  > U R                   R                  nUc   e[        U[        5      (       a  UnO9UR	                  5       S:X  a  [        X5      nO[        UR	                  5       5      eX0;   a  [        TU ]!  U5        g[        R                  " S5      e)z_Delete `group`, `group` can be an object of type :class:`DXFGroup`
or a group name as string.

Nr2   z$GROUP not in group table registered.)rU   r   r}   r~   dxftypeget_group_name	TypeErrorr5   deleter   r   )r:   r   r   ra   r;   s       r<   r  GroupCollection.delete  s~    
 88$$###eS!!D]]_'!%2DEMMO,,<GN4 %%&LMMr>   c                   / nU  HI  u  p4[        [        U5      nUR                  U5        [        U5      (       a  M8  UR	                  U5        MK     U H6  nUR                  [        R                  SU S3S9  U R                  U5        M8     g)z9Removes empty groups and invalid handles from all groups.zRemoved empty group "z".r   N)	r   r#   r   ru   r   r   r   REMOVE_EMPTY_GROUPr  )r:   r   trashra   r   s        r<   r   GroupCollection.audit  s    KD5)EKK u::T"   D22/vR8    KK r>   r   )rU   r   )r   zIterator[DXFGroup])r   r~   )Nr'   T)ra   zOptional[str]r-   r~   r/   r   r   r#   )r   zUnion[DXFGroup, str]r   r   r   )r   r   r   r   r6   r   r   r   r  r  r   r   r   r   s   @r<   r$   r$   f  s^    &
0 #	;; ; 	;
 
;@N( r>   c                    [        SXR                  R                     5      nUR                  5        H  u  p4X@L d  M  Us  $    g)zGet name of `group`.r   r'   )r   rJ   r   items)r   r   group_tablera   rg   s        r<   r  r    s=    |R		%89K#))+?K , r>   )r'   )r   r   rU   r   r   r~   r   r   )r   r~   r   r    r   set[str]r   r   )r   r   )r   r!   r   r  )r   r#   r   r    r   r~   )>
__future__r   typingr   r   r   r   r   r	   
contextlibr
   loggingezdxf.lldxfr   r   ezdxf.lldxf.attributesr   r   r   r   r   ezdxf.auditr   	dxfentityr   r   r   dxfobjr   factoryr   objectcollectionr   rA   r   r   r   ezdxf.documentr   ezdxf.entitiesr   r   ezdxf.entitydbr    ezdxf.layoutsr!   ezdxf.lldxf.tagwriterr"   __all__	getLoggerr   is_integer_boolr`   rG   rN   r#   r   r   rW   r   r$   r  r   r>   r<   <module>r%     sO   #  &  (  # ? ?  $ . 0#&7'%7(
)			7	# sB/ // 	
 // 	

0 ,J7  g
y g
 g
Z !	  	,$$P
X&x0 Xvr>   