
    'j6.                        d dl mZ d dlmZmZmZmZ d dlmZ d dl	m
Z
mZ erd dlmZ d dlmZ ddgZd	Zej        Zd
Zej        ZdZdZ G d d          ZdS )    )annotations)AnyOptionalIteratorTYPE_CHECKING)colors)	validatorconst)Drawing)	DXFEntity
GfxAttribsTRANSPARENCY_BYBLOCK0ByLayer      ?g      c                     e Zd ZU dZeZded<   eZded<   dZ	ded<   e
Zded	<   eZded
<   dZded<   eZded<   eede
ededd=dZd>dZd>dZd?dZd@dAdZd@dBd!Zed>d"            Zej        dCd$            ZedDd%            Zej        dEd'            ZedFd(            Zej        dGd)            Zed>d*            Zej        dCd+            ZedDd,            Zej        dEd-            ZedHd.            Zej        dId/            ZedJd0            Zej        dKd1            Ze dLd4            Z!dMd7Z"e dNd:            Z#e dOd<            Z$dS )Pr   a<  
    Represents often used DXF attributes of graphical entities.

    Args:
        layer (str): layer name as string
        color (int): :ref:`ACI` color value as integer
        rgb: RGB true color (red, green, blue) tuple, each channel value in the
            range from 0 to 255, ``None`` for not set
        linetype (str): linetype name, does not check if the linetype exist!
        lineweight (int):  see :ref:`lineweights` documentation for valid values
        transparency (float): transparency value in the range from 0.0 to 1.0,
            where 0.0 is opaque and 1.0 if fully transparent, -1.0 for
            transparency by block, ``None`` for transparency by layer
        ltscale (float): linetype scaling factor > 0.0, default factor is 1.0

    Raises:
        DXFValueError: invalid attribute value

    str_layerint
_aci_colorNOptional[colors.RGB]_true_color	_linetype_lineweightOptional[float]_transparencyfloat_ltscalelayercolorrgblinetype
lineweighttransparencyltscaler    r!   r"   r#   r$   r%   r&   c               h    || _         || _        || _        || _        || _        || _        || _        d S )Nr   )selfr    r!   r"   r#   r$   r%   r&   s           J/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/gfxattribs.py__init__zGfxAttribs.__init__5   s:     

 $(    returnc                   g }| j         t          k    r|                    d| j          d           | j        t          k    r|                    d| j                    | j        |                    d| j                    | j        t          k    r|                    d| j         d           | j        t          k    r|                    d| j                    | j
        +|                    dt          | j
        d                      | j        t          k    r+|                    d	t          | j        d                      d
                    |          S )Nzlayer=''zcolor=zrgb=z
linetype='zlineweight=ztransparency=   zltscale=z, )r   DEFAULT_LAYERappendr   DEFAULT_ACI_COLORr   r   DEFAULT_LINETYPEr   DEFAULT_LINEWEIGHTr   roundr   DEFAULT_LTSCALEjoin)r(   ss     r)   __str__zGfxAttribs.__str__H   sV   ;-''HH-t{---...?///HH/do//000'HH.D,..///>---HH3$.333444111HH54#355666)HHCU4+=q%A%ACCDDD=O++HH9dmQ 7 799:::yy||r+   c                J    | j         j         d|                                  dS )N())	__class____name__r9   r(   s    r)   __repr__zGfxAttribs.__repr__[   s&    .)==DLLNN====r+   Iterator[tuple[str, Any]]c                D    t          |                                           S )zReturns iter(self).)iteritemsr?   s    r)   __iter__zGfxAttribs.__iter__^   s    DJJLL!!!r+   Flist[tuple[str, Any]]c                   g }|s| j         t          k    r|                    d| j         f           |s| j        t          k    r|                    d| j        f           | j        .|                    dt          j        | j                  f           |s| j        t          k    r|                    d| j        f           |s| j
        t          k    r|                    d| j        f           | j        `| j        t          k    r"|                    dt          j        f           n.|                    dt          j        | j                  f           |s| j        t"          k    r|                    d| j        f           |S )	a   Returns the DXF attributes as list of name, value pairs, returns
        also the default values if argument `default_values` is ``True``.
        The true_color and transparency attributes do not have default values,
        the absence of these attributes is the default value.
        r    r!   N
true_colorr#   r$   r%   r&   )r   r0   r1   r   r2   r   r   rgb2intr   r3   r   r4   r$   r   r   float2transparencyr   r6   )r(   default_valuesdatas      r)   rD   zGfxAttribs.itemsb   s    ') 	0T[M99KK$+./// 	4T_0AAAKK$/2333'KKv~d6F'G'GHIII 	6T^/???KKT^4555 	9T-1CCCKKt7888)!%999^V-HIJJJJ&1$2DEE    	4T]o==KKDM2333r+   dict[str, Any]c                F    t          |                     |                    S )a  Returns the DXF attributes as :class:`dict`, returns also the
        default values if argument `default_values` is ``True``.
        The true_color and transparency attributes do not have default values,
        the absence of these attributes is the default value.
        )dictrD   )r(   rK   s     r)   asdictzGfxAttribs.asdict   s     DJJ~..///r+   c                    | j         S )z
layer name)r   r?   s    r)   r    zGfxAttribs.layer   s     {r+   namec                l    t          j        |          r	|| _        d S t          j        d| d          )Nzinvalid layer name 'r.   )r	   is_valid_layer_namer   r
   DXFValueErrorr(   rR   s     r)   r    zGfxAttribs.layer   s>    (.. 	FDKKK%&DT&D&D&DEEEr+   c                    | j         S )z:ref:`ACI` color value)r   r?   s    r)   r!   zGfxAttribs.color   s     r+   valuec                l    t          j        |          r	|| _        d S t          j        d| d          )Nzinvalid ACI color value 'r.   )r	   is_valid_aci_colorr   r
   rU   r(   rX   s     r)   r!   zGfxAttribs.color   s>    '.. 	L#DOOO%&J%&J&J&JKKKr+   c                    | j         S )zBtrue color value as (red, green, blue) tuple, ``None`` for not set)r   r?   s    r)   r"   zGfxAttribs.rgb        r+   c                    |	d | _         d S t          j        |          r	|| _         d S t          j        d| d          )Nzinvalid true color value 'r.   )r   r	   is_valid_rgbr
   rU   r[   s     r)   r"   zGfxAttribs.rgb   sT    =#D#E** 	M$D%&K5&K&K&KLLLr+   c                    | j         S )zlinetype name)r   r?   s    r)   r#   zGfxAttribs.linetype   s     ~r+   c                l    t          j        |          r	|| _        d S t          j        d| d          )Nzinvalid linetype name 'r.   )r	   is_valid_table_namer   r
   rU   rV   s     r)   r#   zGfxAttribs.linetype   s>    (.. 	I!DNNN%&G&G&G&GHHHr+   c                    | j         S )r$   )r   r?   s    r)   r$   zGfxAttribs.lineweight   r]   r+   c                l    t          j        |          r	|| _        d S t          j        d| d          )Nzinvalid lineweight value 'r.   )r	   is_valid_lineweightr   r
   rU   r[   s     r)   r$   zGfxAttribs.lineweight   sA    (// 	M$D%&K5&K&K&KLLLr+   c                    | j         S )ztransparency value from 0.0 for opaque to 1.0 is fully transparent,
        -1.0 is for transparency by block and ``None`` if for transparency
        by layer
        )r   r?   s    r)   r%   zGfxAttribs.transparency   s     !!r+   c                    |	d | _         d S |t          k    rt          | _         d S t          |t                    rd|cxk    rdk    rn n	|| _         d S t	          j        d| d          )Ng        r   zinvalid transparency value 'r.   )r   r   
isinstancer   r
   rU   r[   s     r)   r%   zGfxAttribs.transparency   s    =!%D***!5Du%% 	O3%+>+>+>+>3+>+>+>+>+>!&D%&MU&M&M&MNNNr+   c                    | j         S )zlinetype scaling factor)r   r?   s    r)   r&   zGfxAttribs.ltscale   s     }r+   c                    t          |t          t          f          r|dk    rt          |          | _        d S t	          j        d| d          )Ngư>zinvalid linetype scale value 'r.   )rh   r   r   r   r
   rU   r[   s     r)   r&   zGfxAttribs.ltscale   sO    eeS\** 	Q!%LLDMMM%&Ou&O&O&OPPPr+   docr   c           
     *   |j         } | |                    dt                    |                    dt                    |                    dt                    |                    dt
                    |                    dt                              S )a  Load default DXF attributes from the HEADER section.

        There is no default true color value and the default transparency is not
        stored in the HEADER section.

        Loads following header variables:

            - ``$CLAYER`` - current layer name
            - ``$CECOLOR`` - current ACI color
            - ``$CELTYPE`` - current linetype name
            - ``$CELWEIGHT`` - current lineweight
            - ``$CELTSCALE`` - current linetype scaling factor

        $CLAYER$CECOLOR$CELTYPE
$CELWEIGHT
$CELTSCALE)r    r!   r#   r$   r&   )headergetr0   r2   r3   r4   r6   )clsrk   rr   s      r)   load_from_headerzGfxAttribs.load_from_header   s|      s**Y66**Z):;;ZZ
,<==zz,0BCCJJ|_==
 
 
 	
r+   	'Drawing'Nonec                    |j         }|j                            | j                  r
| j        |d<   | j        |d<   |j                            | j                  r
| j        |d<   | j        |d<   | j        |d<   dS )a  Write DXF attributes as default values to the HEADER section.

        Writes following header variables:

            - ``$CLAYER`` - current layer name, if a layer table entry exist in `doc`
            - ``$CECOLOR`` - current ACI color
            - ``$CELTYPE`` - current linetype name, if a linetype table entry exist in `doc`
            - ``$CELWEIGHT`` - current lineweight
            - ``$CELTSCALE`` - current linetype scaling factor

        rm   rn   ro   rp   rq   N)	rr   layers	has_entryr    r!   	linetypesr#   r$   r&   )r(   rk   rr   s      r)   write_to_headerzGfxAttribs.write_to_header  s     :
++ 	+ $
F9!Zz=""4=11 	/!%F:#|#||r+   entityr   c                    	 |                                 }n# t          $ r  |             cY S w xY w|                     |          S )z[Get the graphical attributes of an `entity` as :class:`GfxAttribs`
        object.
        )graphic_propertiesAttributeError	from_dict)rt   r}   ds      r)   from_entityzGfxAttribs.from_entity  sV    
	))++AA 	 	 	355LLL	}}Qs    ..r   c                ^    |             }dD ]}||v rt          ||||                    d|v rt          j        |d                   |_        d|v r[|d         }t	          |t
                    r||_        n6|t          j        k    rt          |_        nt          j        |          |_        |S )ak  Construct :class:`GfxAttribs` from a dictionary of raw DXF values.

        Supported attributes are:

            - layer: layer name as string
            - color: :ref:`ACI` value as int
            - true_color: raw DXF integer value for RGB colors
            - rgb: RGB tuple of int or ``None``
            - linetype: linetype name as string
            - lineweight: lineweight as int, see basic concept of :ref:`lineweights`
            - transparency: raw DXF integer value of transparency or a float in the
              range from 0.0 to 1.0
            - ltscale: linetype scaling factor as float

        )r    r!   r#   r$   r&   r"   rH   r%   )	setattrr   int2rgbr"   rh   r   r%   r   transparency2float)rt   r   attribsattrib_namer%   s        r)   r   zGfxAttribs.from_dict!  s    " #%%
 		> 		>K aan===1 .<99GKQ^,L,.. O'3$$!<<<';$$'-'@'N'N$r+   )r    r   r!   r   r"   r   r#   r   r$   r   r%   r   r&   r   )r,   r   )r,   rA   )F)r,   rF   )r,   rM   )rR   r   )r,   r   )rX   r   )r,   r   )rX   r   )r,   r   )rX   r   )r,   r   )rX   r   )rk   r   r,   r   )rk   rv   r,   rw   )r}   r   r,   r   )r   rM   r,   r   )%r>   
__module____qualname____doc__r0   r   __annotations__r2   r   r   r3   r   r4   r   r   r6   r   r*   r9   r@   rE   rD   rP   propertyr    setterr!   r"   r#   r$   r%   r&   classmethodru   r|   r   r    r+   r)   r   r      s         (  F'J''''(,K,,,,%I%%%%)K))))%)M))))%H%%%%
 #&$((,(,(     &   &> > > >" " " "    B0 0 0 0 0    X \F F F \F    X \L L L \L       X  	ZM M M ZM    X _I I I _I       X  M M M M " " " X" O O O O    X ^Q Q Q ^Q 
 
 
 [
0, , , ,*       [  % % % [% % %r+   N)
__future__r   typingr   r   r   r   ezdxfr   ezdxf.lldxfr	   r
   ezdxf.documentr   ezdxf.entitiesr   __all__r0   BYLAYERr2   r3   LINEWEIGHT_BYLAYERr4   r6   r   r   r   r+   r)   <module>r      s   # " " " " " 9 9 9 9 9 9 9 9 9 9 9 9       ( ( ( ( ( ( ( ( )&&&&&&((((((/
0 N  -  o o o o o o o o o or+   