
    Ogg                       U d dl mZ d dlmZmZmZmZ d dlmZm	Z	 d dl
mZ d dlmZ d dlmZ d dlmZmZmZmZmZ d dlmZ d d	lmZ d d
lmZmZmZmZmZmZm Z  d dl!m"Z"m#Z#m$Z$ d dl%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z, er$d dl-m.Z. d dl/m0Z0 d dl
m1Z1 d dl2m3Z3 d dl4m5Z5 d dlm6Z6 g dZ7h dZ8 ed eddejr                         edddejt                         edd dejv                  e!       ed"d dejx                  e!       ed#d$edejz                  ej|                  %       ed&d'edej~                  e%       ed(d ed)       ed*ed+       ed,ed+       ed-edej                  .       ed/ed+       ed0ed+       ed1ed+       ed2edd3       ed4ed+      d5      ZAd6eBd7<    eeA      ZCdBd8ZD G d9 d:e)      ZEej                   G d; d<eE             ZGdCd=ZHdDd>ZIdEd?ZJdFd@ZKyA)G    )annotations)TYPE_CHECKINGOptionalIterableAny)Self	TypeGuard)factory)options)	validator)DXFAttrDXFAttributesDefSubclassRETURN_DEFAULTgroup_code_mapping)colors)const)DXF12DXF2000DXF2004DXF2007DXF2013SUBCLASS_MARKERTRANSPARENCY_BYBLOCK)OCSMatrix44UVec)load_proxy_graphicexport_proxy_graphic   )	DXFEntity
base_classSubclassProcessorDXFTagStorage)Auditor)Drawing)DXFNamespace)
BaseLayout)AbstractTagWriter)xref)	
DXFGraphicacdb_entityacdb_entity_group_codesSeqEnd
add_entityreplace_entityelevation_to_z_axisis_graphic_entityget_font_name>   colorlayerltscalelinetype
color_name
lineweight
true_colortransparency
AcDbEntity   0)defaultr      BYLAYERT)r?   optionalr   >      )r?   rB   r   fixerC   ir  )r?   
dxfversionrB   r   rE   0   g      ?<   )r?   rH   rB   i  )rH   rB   i  i  )rH   rB   r   i  i[  i\  i|  )rH   r?   rB   i  )r5   r7   r4   
paperspacer9   r6   	invisibler:   r8   r;   shadow_modematerial_handlevisualstyle_handleplotstyle_enumplotstyle_handler   r,   c                   | j                  d      rq| j                  }| j                  d       |dk(  ry |D ]H  }| j                  |      }||j                  dk(  s'| j                  ||j                  |             J y y )N	elevationr   )z)hasattrrS   discardgetrT   setreplace)dxfnamesrS   namevs        Z/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/entities/dxfgfx.pyr1   r1      sz     {{;MM	K > 	6DA
 }aii)i45	6      c                  6    e Zd ZU dZdZddiZded<    eee	      Z
	 d,	 	 	 d- fdZd.dZed/d	       Zej                  d0d
       Zej                   d.d       Zed1d       Zej                  d2d       Zed3d       Zed3d       Zd4dZd5dZd6d7dZd8dZd9dZd9dZd:dZd.dZ	 d,	 	 	 	 	 d;dZd<dZd= fdZd>dZd?dZ ed3d       Z!d@dZ"dAdZ#dBd Z$dCd!Z%dDd"Z&dDd#Z'dDd$Z(d3d%Z)	 	 dE	 	 	 	 	 dFd&Z*dGd'Z+d,dH fd(Z,dId)Z-dJ fd*Z.dK fd+Z/ xZ0S )Lr+   zCommon base class for all graphic entities, a subclass of
    :class:`~ezdxf.entities.dxfentity.DXFEntity`. These entities resides in
    entity spaces like modelspace, paperspace or block.
    DXFGFXr5   r>   zdict[str, Any]DEFAULT_ATTRIBSc                B   t         |   |      }||S |j                  }|j                          t        j
                  rG|j                  r|j                  t        k  rd}nd}t        |j                  |rdnd   |      | _
        |j                  |t        d       |S )zAdds subclass processing for 'AcDbEntity', requires previous base
        class processing by parent class.

        (internal API)
        \      r   r    )length_code)superload_dxf_attribsr12 append_base_class_to_acdb_entityr   load_proxy_graphicsrH   r   r   
subclassesproxy_graphicfast_load_dxfattribsr-   )self	processorrZ   ri   code	__class__s        r^   rh   zDXFGraphic.load_dxf_attribs   s     g&y1Jmm224 &&##	(<(<w(F!3$$#Q15 "D 	&&s,CQG
r_   c                    | j                   rZ| j                  j                  | j                   j                  vr-t	        j
                  d| j                  j                   d      yy)z`Post-processing and integrity validation after entity creation.

        (internal API)
        z
Linetype "z" not defined.N)docrZ   r7   	linetypesr   DXFInvalidLineTypero   s    r^   post_new_hookzDXFGraphic.post_new_hook   s[    
 88xx  (:(::.. !2!2 3>B  ; r_   c                    | j                   j                  d      r.t        j                  | j                   j	                  d            S y)zKReturns RGB true color as (r, g, b) tuple or None if true_color is not set.r:   N)rZ   rU   clrint2rgbrW   rw   s    r^   rgbzDXFGraphic.rgb   s5     88L);;txx||L9::r_   c                b    | j                   j                  dt        j                  |             y)zSet RGB true color as (r, g , b) tuple e.g. (12, 34, 56).

        Raises:
            TypeError: input value `rgb` has invalid type
        r:   N)rZ   rX   rz   rgb2int)ro   r|   s     r^   r|   zDXFGraphic.rgb   s     	\3;;s#34r_   c                :    | j                   j                  d       y)zDelete RGB true color value.r:   N)rZ   rV   rw   s    r^   r|   zDXFGraphic.rgb   s     	&r_   c                    | j                   j                  d      rO| j                   j                  d      }t        j                  |      r|t
        z  ryt        j                  |      S y)zGet transparency as float value between 0 and 1, 0 is opaque and 1
        is 100% transparent (invisible). Transparency by block returns always 0.
        r;   g        )rZ   rU   rW   r   is_transparencyr   rz   transparency2float)ro   values     r^   r;   zDXFGraphic.transparency   sV    
 88N+HHLL0E((///--e44r_   c                b    | j                   j                  dt        j                  |             y)ztSet transparency as float value between 0 and 1, 0 is opaque and 1
        is 100% transparent (invisible).
        r;   N)rZ   rX   rz   float2transparency)ro   r;   s     r^   r;   zDXFGraphic.transparency  s!    
 	^S%;%;L%IJr_   c                :    | j                   j                  d       S )z<Returns ``True`` if entity inherits transparency from layer.r;   )rZ   rU   rw   s    r^   is_transparency_by_layerz#DXFGraphic.is_transparency_by_layer  s     88##N333r_   c                H    | j                   j                  dd      t        k(  S )z<Returns ``True`` if entity inherits transparency from block.r;   r   )rZ   rW   r   rw   s    r^   is_transparency_by_blockz#DXFGraphic.is_transparency_by_block  s     xx||NA.2FFFr_   c                    t               }t        D ]<  }| j                  j                  |      s| j                  j	                  |      ||<   > |S )zReturns the important common properties layer, color, linetype,
        lineweight, ltscale, true_color and color_name as `dxfattribs` dict.
        )dictGRAPHIC_PROPERTIESrZ   rU   rW   )ro   attribskeys      r^   graphic_propertieszDXFGraphic.graphic_properties  sI     &% 	1Cxx$#xx||C0	1 r_   c                    | j                   j                  d      r(| j                   j                  dd      }t        |      S t               S )zReturns object coordinate system (:ref:`ocs`) for 2D entities like
        :class:`Text` or :class:`Circle`, returns a pass-through OCS for
        entities without OCS support.
        	extrusion)r   r   r    )r?   )rZ   is_supportedrW   r   )ro   r   s     r^   ocszDXFGraphic.ocs"  s=     88  -[)DIy>!5Lr_   c                    || j                   _        |r|| j                   _        y| j                   j                  d       y)z7Set owner attribute and paperspace flag. (internal API)rK   N)rZ   ownerrK   rV   )ro   r   rK   s      r^   	set_ownerzDXFGraphic.set_owner.  s.    ",DHHHH\*r_   c                     y)zStore linked or attached entities. Same API for both types of
        appended data, because entities with linked entities (POLYLINE, INSERT)
        have no attached entities and vice versa.

        (internal API)
        N )ro   entitys     r^   link_entityzDXFGraphic.link_entity6  s     	r_   c                &    | j                  |       y)z7Export entity specific data as DXF tags. (internal API)N)export_acdb_entity)ro   	tagwriters     r^   export_entityzDXFGraphic.export_entity?  s     		*r_   c                N   |j                   t        kD  }|r$|j                  t        t        j
                         | j                  j                  |g d       | j                  rB|r?t        j                  r.t        | j                  ||j                   t        k  rdnd       yyyy)z8Export subclass 'AcDbEntity' as DXF tags. (internal API))rK   r5   r7   rN   r4   r9   r6   rL   r:   r8   r;   rP   rQ   rM   rO   rd   re   )r   rf   N)rH   r   
write_tag2r   r,   r\   rZ   export_dxf_attribsrm   r   store_proxy_graphicsr   r   )ro   r   not_r12s      r^   r   zDXFGraphic.export_acdb_entityE  s     &&.  +2B2BC##	
* 'g.J.J ""##,#7#7'#ARs /K'r_   c                   | j                   j                  | j                  y	 | j                  j                  j	                  | j                   j                        S # t
        j                  $ r Y nw xY w	 | j                  j                  j                  | j                   j                        S # t
        j                  $ r Y yw xY w)zfReturns the owner layout or returns ``None`` if entity is not
        assigned to any layout.
        N)
rZ   r   rt   layoutsget_layout_by_keyr   DXFKeyErrorblocksget_block_layout_by_handleDXFTableEntryErrorrw   s    r^   
get_layoutzDXFGraphic.get_layouti  s     88>>!TXX%5	88##55dhhnnEE   			88??==dhhnnMM'' 		s#   8A A43A488B1 1CCc                    | j                   st        d      | j                  d| j                  _        y| j                         }|r|j                  |        yy)a-  
        Unlink entity from associated layout. Does nothing if entity is already
        unlinked.

        It is more efficient to call the
        :meth:`~ezdxf.layouts.BaseLayout.unlink_entity` method of the associated
        layout, especially if you have to unlink more than one entity.
        z Can not unlink destroyed entity.N)is_alive	TypeErrorrt   rZ   r   r   unlink_entity)ro   layouts     r^   unlink_from_layoutzDXFGraphic.unlink_from_layoutx  sQ     }}>??88!DHHN"  & r_   c                z    |'| j                         }|t        j                  d      |j                  | |       y)a  
        Move entity from model space or a paper space layout to another layout.
        For block layout as source, the block layout has to be specified. Moving
        between different DXF drawings is not supported.

        Args:
            layout: any layout (model space, paper space, block)
            source: provide source layout, faster for DXF R12, if entity is
                    in a block layout

        Raises:
            DXFStructureError: for moving between different DXF drawings
        Nz#Source layout for entity not found.)r   r   DXFValueErrormove_to_layout)ro   r   sources      r^   r   zDXFGraphic.move_to_layout  s<      >__&F~))*OPPdF+r_   c                    | j                   |j                   k7  rt        j                  d      | j                         }|j	                  |       |S )a_  
        Copy entity to another `layout`, returns new created entity as
        :class:`DXFEntity` object. Copying between different DXF drawings is
        not supported.

        Args:
            layout: any layout (model space, paper space, block)

        Raises:
            DXFStructureError: for copying between different DXF drawings
        z8Copying between different DXF drawings is not supported.)rt   r   DXFStructureErrorcopyr/   )ro   r   
new_entitys      r^   copy_to_layoutzDXFGraphic.copy_to_layout  sK     88vzz!))J  YY[
*%r_   c                P   | j                   |j                   u sJ d       | j                  syt        |   |       |j	                  |        | j
                  }|j                  d      r|j                  |        |j                  d      r|j                  |        |j                  d      r|j                  |        |j                  d      r|j                  |        |j                  d      r|j                  |        |j                  d      r|j                  |        yy)	aJ  Audit and repair graphical DXF entities.

        .. important::

            Do not delete entities while auditing process, because this
            would alter the entity database while iterating, instead use::

                auditor.trash(entity)

            to delete invalid entities after auditing automatically.
        z#Auditor for different DXF document.Nr5   r7   r4   r9   r   r;   )rt   r   rg   auditcheck_owner_existrZ   rU   check_for_valid_layer_namecheck_entity_linetypecheck_entity_color_indexcheck_entity_lineweightcheck_extrusion_vectorcheck_transparency)ro   auditorrZ   rr   s      r^   r   zDXFGraphic.audit  s     xx7;;&M(MM&}}g!!$'hh;;w..t4;;z"))$/;;w,,T2;;|$++D1;;{#**40;;~&&&t, 'r_   c                    t               )zInplace transformation interface, returns `self` (floating interface).

        Args:
             m: 4x4 transformation matrix (:class:`ezdxf.math.Matrix44`)
        )NotImplementedErrorro   ms     r^   	transformzDXFGraphic.transform  s     "##r_   c                T    | j                   | j                   j                  |       yy)zBShould be called if the main entity transformation was successful.N)xdatar   r   s     r^   post_transformzDXFGraphic.post_transform  s#    ::!JJ  # "r_   c                    | j                   duS )z)Check if post transform call is required.N)r   rw   s    r^   is_post_transform_requiredz%DXFGraphic.is_post_transform_required  s     zz%%r_   c                N    | j                  t        j                  |||            S )zTranslate entity inplace about `dx` in x-axis, `dy` in y-axis and
        `dz` in z-axis, returns `self` (floating interface).

        Basic implementation uses the :meth:`transform` interface, subclasses
        may have faster implementations.
        )r   r   	translate)ro   dxdydzs       r^   r   zDXFGraphic.translate  s"     ~~h00R<==r_   c                N    | j                  t        j                  |||            S )zScale entity inplace about `dx` in x-axis, `dy` in y-axis and `dz`
        in z-axis, returns `self` (floating interface).
        r   r   scale)ro   sxsyszs       r^   r   zDXFGraphic.scale  s      ~~hnnRR899r_   c                J    | j                  t        j                  |            S )zzScale entity inplace uniform about `s` in x-axis, y-axis and z-axis,
        returns `self` (floating interface).
        r   )ro   ss     r^   scale_uniformzDXFGraphic.scale_uniform  s     ~~hnnQ/00r_   c                L    | j                  t        j                  ||            S )zRotate entity inplace about vector `axis`, returns `self`
        (floating interface).

        Args:
            axis: rotation axis as tuple or :class:`Vec3`
            angle: rotation angle in radians
        )r   r   axis_rotate)ro   axisangles      r^   rotate_axiszDXFGraphic.rotate_axis  s      ~~h224?@@r_   c                J    | j                  t        j                  |            S )zRotate entity inplace about x-axis, returns `self`
        (floating interface).

        Args:
            angle: rotation angle in radians
        )r   r   x_rotatero   r   s     r^   rotate_xzDXFGraphic.rotate_x	       ~~h//677r_   c                J    | j                  t        j                  |            S )zRotate entity inplace about y-axis, returns `self`
        (floating interface).

        Args:
            angle: rotation angle in radians
        )r   r   y_rotater   s     r^   rotate_yzDXFGraphic.rotate_y  r   r_   c                J    | j                  t        j                  |            S )zRotate entity inplace about z-axis, returns `self`
        (floating interface).

        Args:
            angle: rotation angle in radians
        )r   r   z_rotater   s     r^   rotate_zzDXFGraphic.rotate_z  r   r_   c                L    t        | j                        xr d| j                  v S )z5Returns ``True`` if entity has an attached hyperlink.PE_URL)boolr   rw   s    r^   has_hyperlinkzDXFGraphic.has_hyperlink$  s    DJJ<X%;<r_   c                   ddt        |      fg}|r\|j                  d       |j                  dt        |      f       |r|j                  dt        |      f       |j                  d       | j                  d       | j                  d|       | j                  r=d| j                  j
                  vr%| j                  j
                  j                  d       | S )zSet hyperlink of an entity.)i  r     )  {)r   }r   )strappenddiscard_xdata	set_xdatart   appidsnew)ro   linkdescriptionlocationr   s        r^   set_hyperlinkzDXFGraphic.set_hyperlink(  s     "D#d)#45LL%LL$K 012dCM23LL%8$x'887HHOO)r_   c                2   d}d}d}| j                   r|d| j                   v rn| j                  d      D cg c]  }|j                  dk(  s|j                    }}t	        |      r|d   }t	        |      dkD  r|d   }t	        |      dkD  r|d   }|||fS c c}w )z,Returns hyperlink, description and location. r   r   r   r       )r   	get_xdatarq   r   len)ro   r   r   r   tagr   s         r^   get_hyperlinkzDXFGraphic.get_hyperlink=  s    ::(djj0*...*BW3chhRVFVSYYWEW5zQx5zA~#Ah5zA~ 8[(** Xs   B	Bc                   | j                   syt        | 	  |       |duxr" | j                  j                  |j
                  v }|sd| j                  _        | j                  j                  d       | j                  j                  d       | j                  j                  d       | j                  j                  d       y)zORemove all dependencies from current document.

        (internal API)
        NrA   rN   rO   rP   rQ   )r   rg   remove_dependenciesrZ   r7   ru   rV   )ro   otherhas_linetyperr   s      r^   r  zDXFGraphic.remove_dependenciesL  s    
 }}#E* D(Sdhh.?.?5??.R )DHH*+-.)*+,r_   c                h   |xs i }d|vr| j                   j                  |d<   | j                  r"t        j                  ||| j                        }nt        j
                  ||      }| j                   j                  |j                   _        | j                   j                  |j                   _        |S )zCreate and bind  new entity with same layout settings as `self`.

        Used by INSERT & POLYLINE to create appended DXF entities, don't use it
        to create new standalone entities.

        (internal API)
        r5   )rZ   r5   rt   r
   create_db_entryr   r   rK   )ro   type_
dxfattribsr   s       r^   _new_compound_entityzDXFGraphic._new_compound_entity`  s      %2

 *$"&((..Jw88,,UJIF[[
3F88>>

 $ 3 3

r_   c                    t         |   |       | j                  }|j                  |j                         |j                  |j                         |j                  |j                  d             y)z5Register required resources to the resource registry.rN   N)	rg   register_resourcesrZ   	add_layerr5   add_linetyper7   
add_handlerW   )ro   registryrZ   rr   s      r^   r  zDXFGraphic.register_resourcesw  sU    "8,hh399%cll+CGG$567r_   c                   t         |   ||       |j                  | j                  j                        |j                  _        | j                  j
                  } |d      r4|j                  | j                  j                        |j                  _         |d      r4|j                  | j                  j                        |j                  _	        |j                  j                  d       |j                  j                  d       y)z3Translate resources from self to the copied entity.r7   rN   rO   rQ   N)rg   map_resources	get_layerrZ   r5   rU   get_linetyper7   
get_handlerN   rV   )ro   clonemappingattrib_existrr   s       r^   r  zDXFGraphic.map_resources  s    eW-!++DHHNN;		xx''
#!(!5!5dhh6G6G!HEII)*(/(:(:488;S;S(TEII% 			./		,-r_   Nrp   zOptional[SubclassProcessor]returnr'   )r   None)r   ztuple[int, int, int] | None)r|   zclr.RGB | tuple[int, int, int]r   r!  )r   float)r;   r"  r   r!  )r   r   )r   r   )r   r   )r   )r   Optional[str]rK   intr   r!  )r   r!   r   r!  )r   r)   r   r!  )r   Optional[BaseLayout])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"  r   r   )r   r"  r   r   )r   r   r   r"  r   r   )r   r"  r   r   )NN)r   r   r   r#  r   r#  )r   ztuple[str, str, str])r	  zOptional[Drawing]r   r!  )r  r   r   r   )r  zxref.Registryr   r!  )r  r   r  zxref.ResourceMapperr   r!  )1__name__
__module____qualname____doc__DXFTYPErb   __annotations__r   r"   r,   
DXFATTRIBSrh   rx   propertyr|   setterdeleterr;   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  __classcell__rr   s   @r^   r+   r+      s   
 G'.nO^4z;7J 8<4	<	   	ZZ5 5 	[[' ' 
 
 K K 4 4 G G
++"H', BF, ,*>,	,,*-@$$
 & &>:1A888= &*"&	 #  	*+-(.8. .r_   r+   c                  .     e Zd ZdZ	 d	 	 	 d fdZ xZS )r.   SEQENDc                ^    t         t        |   |      }|r|j                  |t               |S )z!Loading interface. (internal API))rg   r+   rh   simple_dxfattribs_loaderr-   )ro   rp   rZ   rr   s      r^   rh   zSeqEnd.load_dxf_attribs  s/    
 J6yA..s4KL
r_   r  r  )r&  r'  r(  r*  rh   r0  r1  s   @r^   r.   r.     s'    G 8<4	 r_   r.   c                    | j                   j                  J |J |j                  r t        j                  | |j                         |j                  |        y)zEAdd `entity` entity to the entity database and to the given `layout`.N)rZ   handlert   r
   bindr/   )r   r   s     r^   r/   r/     sK    ::$$$zzVVZZ(
fr_   c                L   |j                   j                  J |J | j                   j                  |j                   _        | |v rO|j                  |        |j                  r t	        j
                  ||j                         |j                  |       y| j                          y)zAdd `target` entity to the entity database and to the given `layout`
    and replace the `source` entity by the `target` entity.
    N)rZ   r7  delete_entityrt   r
   r8  r/   destroy)r   targetr   s      r^   r0   r0     s     ::$$$

))FJJV$::LL,&!r_   c                `    t        | t              ryt        | t              r| j                  ryy)zReturns ``True`` if the `entity` has a graphical representations and
    can reside in the model space, a paper space or a block layout,
    otherwise the entity is a table or class entry or a DXF object from the
    OBJECTS section.
    TF)
isinstancer+   r$   r2   )r   s    r^   r2   r2     s)     &*%&-(V-E-Er_   c                h   t         j                  }| j                  }||S 	 | j                  j	                  dt         j
                        }	 |j                  j	                  |      }|j                  j                  S # t         j                  $ r |cY S w xY w# t         j                  $ r |cY S w xY w)zReturns the font name of any DXF entity.

    This function always returns a font name even if the entity doesn't support text
    styles.  The default font name is "txt".
    style)
r   DEFAULT_TEXT_FONTrt   rZ   rW   DEFAULT_TEXT_STYLEDXFAttributeErrorstylesfontr   )r   	font_namert   
style_namer@  s        r^   r3   r3     s     ''I
**C
{ZZ^^GU-E-EF


z*yy~~	 "" 
 ## s#   *A> 0B >BBB10B1N)rZ   r'   r[   zIterable[str])r   r+   r   r(   r   r!  )r   r+   r<  r+   r   r(   r   r!  )r   r!   r   zTypeGuard[DXFGraphic])r   r!   r   r   )L
__future__r   typingr   r   r   r   typing_extensionsr   r	   ezdxf.entitiesr
   ezdxfr   ezdxf.lldxfr   ezdxf.lldxf.attributesr   r   r   r   r   r   rz   r   ezdxf.lldxf.constr   r   r   r   r   r   r   
ezdxf.mathr   r   r   ezdxf.proxygraphicr   r   	dxfentityr!   r"   r#   r$   ezdxf.auditr%   ezdxf.documentr&   r'   ezdxf.layoutsr(   ezdxf.lldxf.tagwriterr)   r*   __all__r   is_valid_layer_nameis_valid_table_nameis_valid_aci_coloris_integer_boolis_valid_lineweightfix_lineweightis_positiver   r,   r+  r-   r1   r+   register_entityr.   r/   r0   r2   r3   r   r_   r^   <module>r`     s(   # 9 9 - "  !       + * G N N#&+(7
	  ' C93P3PQ33	
 22 
 // 
 33**
 ++ 
 RwN cgEcgE  //	
 swF"37TJ%cgM "#'1tT $CGdKWPS[ Sh -[9 68\. \.~ 	Z   
r_   