
    'j0                       d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
 d dlZd dlZd dlmZmZmZmZ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 d dlmZ d dl m!Z! e	rd d	l"m#Z# g d
Z$dZ% ej&        d          Z' G d dej(                  Z) G d d          Z*d;dZ+d;dZ,	 d<d=dZ-d>dZ.d?dZ/d@d"Z0dAd%Z1dBd(Z2dCd,Z3dDd.Z4dDd/Z5dDd0Z6dEd2Z7dFd4Z8dGd6Z9dHd8Z:dId:Z;dS )J    )annotations)IterableIterator
NamedTupleOptionalTupleListTYPE_CHECKINGSequenceN)Matrix44UVecVec3NonUniformScalingErrorInsertTransformationError)	DXFEntity
DXFGraphicCircle
LWPolylinePolylineEllipseis_graphic_entity)default_copyCopyNotSupported)SupportsTemporaryTransformation)Drawing)BlockLayout)LoggerErrorinplacecopies	translatescale_uniformscalex_rotatey_rotatez_rotateaxis_rotatetransform_entity_by_blockreftransform_entities_by_blockrefg-q=ezdxfc                      e Zd ZdZ ej                    Z ej                    Z ej                    Z ej                    Z	 ej                    Z
dS )r   r   N)__name__
__module____qualname__NONEenumautoTRANSFORMATION_NOT_SUPPORTEDCOPY_NOT_SUPPORTEDNON_UNIFORM_SCALING_ERRORINSERT_TRANSFORMATION_ERRORVIRTUAL_ENTITY_NOT_SUPPORTED     I/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/transform.pyr   r   ;   s[        D#,49;; " )	"+$)++#,49;;   r8   r   c                  b    e Zd Z G d de          ZddZddZdd
ZddZddZ	ddZ
ddZdS ) r   c                  .    e Zd ZU ded<   ded<   ded<   dS )Logger.Entryr   errorstrmessager   entityN)r,   r-   r.   __annotations__r7   r8   r9   Entryr<   E   s0         r8   rB   returnNonec                    g | _         d S N_entriesselfs    r9   __init__zLogger.__init__J   s    ,.r8   indexintc                    | j         |         S )z#Returns the error entry at `index`.rG   )rJ   rL   s     r9   __getitem__zLogger.__getitem__M   s    }U##r8   Iterator[Entry]c                *    t          | j                  S )z Iterates over all error entries.)iterrH   rI   s    r9   __iter__zLogger.__iter__Q   s    DM"""r8   c                *    t          | j                  S )z#Returns the count of error entries.)lenrH   rI   s    r9   __len__zLogger.__len__U   s    4=!!!r8   r=   r   r?   r>   r@   r   c                n    | j                             t                              |||                     d S rF   )rH   appendr   rB   )rJ   r=   r?   r@   s       r9   addz
Logger.addY   s.    V\\%&AABBBBBr8   	list[str]c                $    d | j         D             S )z.Returns all error messages as list of strings.c                    g | ]	}|j         
S r7   )r?   ).0entrys     r9   
<listcomp>z#Logger.messages.<locals>.<listcomp>^   s    999%999r8   rG   rI   s    r9   messageszLogger.messages\   s    994=9999r8   entriesIterable[Entry]c                f    |D ]-}	 | j                             |           # t          $ r Y *w xY wd S rF   )rH   remove
ValueError)rJ   ra   r^   s      r9   purgezLogger.purge`   sY     	 	E$$U++++   	 	s   !
..N)rC   rD   )rL   rM   rC   rB   )rC   rP   )rC   rM   )r=   r   r?   r>   r@   r   )rC   rZ   )ra   rb   rC   rD   )r,   r-   r.   r   rB   rK   rO   rS   rV   rY   r`   rf   r7   r8   r9   r   r   D   s            
   
/ / / /$ $ $ $# # # #" " " "C C C C: : : :     r8   r   entitiesIterable[DXFEntity]mr   rC   c                   t                      }| D ]}|j        s
	 |                    |           !# t          t          f$ r4 |                    t          j        t          |           d|           Y et          $ r4 |                    t          j
        t          |           d|           Y t          $ r4 |                    t          j        t          |           d|           Y w xY w|S )aW  Transforms the given `entities` inplace by the transformation matrix `m`,
    non-uniform scaling is not supported. The function logs errors and does not raise
    errors for unsupported entities or transformations that cannot be performed,
    see enum :class:`Error`.
    The :func:`inplace` function supports virtual entities as well.

    ' entity does not support transformation, entity does not support non-uniform scalingC entity can not represent a non-orthogonal target coordinate system)r   is_alive	transformAttributeErrorNotImplementedErrorrY   r   r2   r>   r   r4   r   r5   )rg   ri   logr@   s       r9   _inplacers   h   sF    ((C   		Q 34 	 	 	GG2v;;GGG    
 & 	 	 	GG/v;;LLL    
 ) 	 	 	GG1v;;ccc    	 Js   2AC/6:C/2:C/.C/c                   t          | |          }g }|D ]J}|j        t          j        k    r|j        }|j        rG|                    |           |                    t          j        dt          |           |           nt          |t                    rA|                    |           |                    d          }|                    |           t          |t          t          f          rj|                    |           |                                D ]@}t          |t                    r|                                }|                    |           AL|                    |           |S )a3  Transforms the given `entities` inplace by the transformation matrix `m`,
    non-uniform scaling is supported. The function converts circular arcs into ellipses
    to perform non-uniform scaling.  The function logs errors and does not raise errors
    for unsupported entities or transformation errors, see enum :class:`Error`.

    .. important::

        The :func:`inplace` function does not support type conversion for virtual
        entities e.g. non-uniform scaling for CIRCLE, ARC or POLYLINE with bulges,
        see also function :func:`copies`.

    z8non-uniform scaling is not supported for virtual entity T)replace)rs   r=   r   r4   r@   
is_virtualrX   rY   r6   r>   
isinstancer   
to_ellipsero   r   r   exploderf   )rg   ri   rr   errorsr^   r@   ellipse
sub_entitys           r9   r   r      sx     8Q

C!#F ( (;%999 	MM%   GG2X3v;;XX  
 ff%% 		(MM%   '''55Ga    X 677 	(MM%   $nn.. ( (
j&11 9!+!6!6!8!8J$$Q''''IIfJr8   Optional[Matrix44]Tuple[Logger, List[DXFEntity]]c                    t                      }t          | |          }t          |t                    rt	          |||          }||fS )a  Copy entities and transform them by matrix `m`. Does not raise any exception
    and ignores all entities that cannot be copied or transformed. Just copies the input
    entities if matrix `m` is ``None``. Returns a tuple of :class:`Logger` and a list of
    transformed virtual copies. The function supports virtual entities as input and
    converts circular arcs into ellipses to perform non-uniform scaling.
    )r   _copy_entitiesrw   r   _transform_clones)rg   ri   rr   cloness       r9   r    r       sI     ((CHc**F!X 3"61c22;r8   rr   list[DXFEntity]c                   g }| D ]|}|j         s
	 |                    t                    }|                    |           <# t          $ r4 |                    t          j        t          |           d|           Y yw xY w|S )N)copy_strategyz entity does not support copy)	rn   copyr   rX   r   rY   r   r3   r>   )rg   rr   r   r@   clones        r9   r   r      s     F ! ! 			!KKlK;;E MM%       	 	 	GG(v;;===    	 Ms   A;A?>A?r   c           	     X   g }| D ]#}	 |                     |           |                    |           /# t          t          f$ r4 |                    t
          j        t          |           d|           Y st          $ r4 |                    t
          j	        t          |           d|           Y t          $ rj 	 |                    t          ||                     nA# t          $ r4 |                    t
          j        t          |           d|           Y nw xY wY !w xY w|S )Nrk   rm   rl   )ro   rX   rp   rq   rY   r   r2   r>   r   r5   r   extend_scale_non_uniform	TypeErrorr4   )r   ri   rr   rg   r@   s        r9   r   r      s    "H $ $	$Q. OOF####-  34 	 	 	GG2v;;GGG    
 ) 	 	 	GG1v;;ccc    
 & 	 	 	 261 = =>>>>   36{{PPP    	 Os@   4AD'8:D'4	D'>#C"!D'";D D'D  D'&D'r@   r   c              #    K   t          | t                    r/t          j        |           }|                    |           |V  d S t          | t
          t          f          r[|                                 D ]D}t          |t                    rt          j        |          }|                    |           |V  Ed S t          rF   )	rw   r   r   from_arcro   r   r   virtual_entitiesr   )r@   ri   r|   s      r9   r   r      s      &&!! %f--
Q	FZ2	3	3  1133 	 	J*f-- :$-j99
  ###		 	 r8   offsetr   c                    t          |          }|r4t          | t          j        |j        |j        |j                            S t                      S )z=Translates (moves) `entities` inplace by the `offset` vector.ri   )r   rs   r   r!   xyzr   )rg   r   vs      r9   r!   r!     sG    VA GH$6qsAC$E$EFFFF88Or8   factorfloatc                    t          |          }t          |          t          k    r%t          | t	          j        |||                    S t                      S )zScales `entities` inplace by a `factor` in all axis. Scaling factors smaller than
    :attr:`MIN_SCALING_FACTOR` are ignored.

    r   )r   absMIN_SCALING_FACTORrs   r   r#   r   )rg   r   fs      r9   r"   r"     sK    
 	fA
1vv"""HN1a$;$;<<<<88Or8   sxsyszc           
         dd}t          | t          j         ||           ||           ||                              S )a  Scales `entities` inplace by the factors `sx` in x-axis, `sy` in y-axis and `sz`
    in z-axis. Scaling factors smaller than :attr:`MIN_SCALING_FACTOR` are ignored.

    .. important::

        same limitations for virtual entities as the :func:`inplace` function

    r   r   rC   c                X    t          |           } t          |           t          k    r| ndS )Ng      ?)r   r   r   )r   s    r9   safezscale.<locals>.safe+  s(    !HHFF///qqS8r8   )r   r   rC   r   )r   r   r#   )rg   r   r   r   r   s        r9   r#   r#   !  sN    9 9 9 9 8X^DDHHdd2hhRIIJJJr8   anglec                    t          |          }|r#t          | t          j        |                    S t	                      S zBRotates `entities` inplace by `angle` in radians about the x-axis.r   )r   rs   r   r$   r   rg   r   as      r9   r$   r$   2  <    eA :H$5a$8$8999988Or8   c                    t          |          }|r#t          | t          j        |                    S t	                      S )zBRotates `entities` inplace by `angle` in radians about the y-axis.r   )r   rs   r   r%   r   r   s      r9   r%   r%   :  r   r8   c                    t          |          }|r#t          | t          j        |                    S t	                      S r   )r   rs   r   r&   r   r   s      r9   r&   r&   B  r   r8   axisc                    t          |          }|st                      S t          |          }|j        s$t	          | t          j        ||                    S t                      S )zRotates `entities` inplace by `angle` in radians about the rotation axis starting
    at the origin pointing in `axis` direction.
    r   )r   r   r   is_nullrs   r   r'   )rg   r   r   r   r   s        r9   r'   r'   J  s_     	eA xxT

A9 @H$8A$>$>????88Or8   boolc                (    t          | g|          duS )zApply a transformation by moving an entity into a block and replacing the entity
    by a block reference with the applied transformation.
    N)_transform_by_blockref)r@   ri   s     r9   r(   r(   X  s     "6(A..d::r8   BlockLayout | Nonec                <    t          t          |           |          S )zApply a transformation by moving entities into a block and replacing the entities
    by a block reference with the applied transformation.
    )r   list)rg   ri   s     r9   r)   r)   _  s     "$x..!444r8   Sequence[DXFEntity]c                T   t          |           dk    rd S | d         }t          |          sd S |j        }|d S |                                }|d S |j                                        }|                    |j        d          }	 |                    |           na# t          $ rT t                              d           |                    |           |j                            |j        d           Y d S w xY w| D ]'}t          |          r|                    ||           (|S )Nr   )r   r   r   z#cannot apply invalid transformationF)r   )rU   r   doc
get_layoutblocksnew_anonymous_blockadd_blockrefnamero   r   loggerwarningdelete_entitydelete_blockmove_to_layout)rg   ri   first_entityr   layoutblockinsertes           r9   r   r   h  sN    8}}tA;L\** t

C
{t$$&&F~tJ**,,E  Y77F$   =>>>V$$$

777tt	  , ,Q 	,!!!U+++Ls   B AC;:C;rD   c                    | D ]@}t          |t                    r)|                                }|                    |           Ad S rF   )rw   r   temporary_transformationapply_transformation)rg   r@   tts      r9   apply_temporary_transformationsr     sT     , ,f=>> 	,0022B##F+++, ,r8   )rg   rh   ri   r   rC   r   rF   )rg   rh   ri   r}   rC   r~   )rg   rh   rr   r   rC   r   )r   rh   ri   r   rr   r   )r@   r   ri   r   )rg   rh   r   r   rC   r   )rg   rh   r   r   rC   r   )
rg   rh   r   r   r   r   r   r   rC   r   )rg   rh   r   r   rC   r   )rg   rh   r   r   r   r   rC   r   )r@   r   ri   r   rC   r   )rg   rh   ri   r   rC   r   )rg   r   ri   r   rC   r   )rg   rh   rC   rD   )<
__future__r   typingr   r   r   r   r   r	   r
   r   r0   logging
ezdxf.mathr   r   r   r   r   ezdxf.entitiesr   r   r   r   r   r   r   ezdxf.entities.copyr   r   ezdxf.protocolsr   ezdxf.documentr   ezdxf.layoutsr   __all__r   	getLoggerr   Enumr   r   rs   r   r    r   r   r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r   r   r7   r8   r9   <module>r      sz   # " " " " "	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	                                 ? > > > > > > > ; ; ; ; ; ; " " " " " " *))))))    		7	#	#/ / / / /DI / / /! ! ! ! ! ! ! !H! ! ! !H, , , ,` <@    "   $   @          K K K K"            ; ; ; ;5 5 5 5   D, , , , , ,r8   