
    Og0                       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jL                  d      Z' G d dejP                        Z) G d d      Z*d"dZ+	 	 	 	 	 	 d"dZ,	 d#	 	 	 	 	 d$dZ-d%dZ.d&dZ/d'dZ0d(dZ1d)dZ2d*dZ3d+dZ4d+dZ5d+dZ6d,dZ7d-dZ8	 	 	 	 	 	 d.dZ9	 	 	 	 	 	 d/d Z:d0d!Z;y)1    )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
y)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     T/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/transform.pyr   r   ;   sM    D#,499; " )		"+$))+#,499; r8   r   c                  Z    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y
)r   c                  ,    e Zd ZU ded<   ded<   ded<   y)Logger.Entryr   errorstrmessager   entityN)r,   r-   r.   __annotations__r7   r8   r9   Entryr<   E   s    r8   rB   c                    g | _         y N_entriesselfs    r9   __init__zLogger.__init__J   s	    ,.r8   c                     | j                   |   S )z#Returns the error entry at `index`.rE   )rH   indexs     r9   __getitem__zLogger.__getitem__M   s    }}U##r8   c                ,    t        | j                        S )z Iterates over all error entries.)iterrF   rG   s    r9   __iter__zLogger.__iter__Q   s    DMM""r8   c                ,    t        | j                        S )z#Returns the count of error entries.)lenrF   rG   s    r9   __len__zLogger.__len__U   s    4==!!r8   c                d    | j                   j                  t        j                  |||             y rD   )rF   appendr   rB   )rH   r=   r?   r@   s       r9   addz
Logger.addY   s!    V\\%&ABr8   c                T    | j                   D cg c]  }|j                   c}S c c}w )z.Returns all error messages as list of strings.)rF   r?   )rH   entrys     r9   messageszLogger.messages\   s    +/==9%999s   %c                h    |D ]  }	 | j                   j                  |         y # t        $ r Y -w xY wrD   )rF   remove
ValueError)rH   entriesrW   s      r9   purgezLogger.purge`   s<     	E$$U+	  s   %	11N)returnNone)rK   intr^   rB   )r^   zIterator[Entry])r^   r`   )r=   r   r?   r>   r@   r   )r^   z	list[str])r\   zIterable[Entry]r^   r_   )r,   r-   r.   r   rB   rI   rL   rO   rR   rU   rX   r]   r7   r8   r9   r   r   D   s2    
 
/$#"C:r8   r   c                   t               }| D ]!  }|j                  s	 |j                  |       # |S # t        t        f$ r0 |j                  t        j                  t        |       d|       Y dt        $ r0 |j                  t        j                  t        |       d|       Y t        $ r0 |j                  t        j                  t        |       d|       Y w xY w)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NotImplementedErrorrU   r   r2   r>   r   r4   r   r5   )entitiesmlogr@   s       r9   _inplacerl   h   s     (C 	Q	0 J'  34 	GG22v;-FG
 & 	GG//v;-KL
 ) 	GG11v;-bc	s   3<C 15C (5C C c                   t        | |      }g }|D ]+  }|j                  t        j                  k7  r"|j                  }|j
                  r?|j                  |       |j                  t        j                  dt        |       |       yt        |t              r5|j                  |       |j                  d      }|j                  |       t        |t        t        f      s|j                  |       |j!                         D ]3  }t        |t              r|j                         }|j                  |       5 . |j#                  |       |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)rl   r=   r   r4   r@   
is_virtualrT   rU   r6   r>   
isinstancer   
to_ellipserf   r   r   exploder]   )ri   rj   rk   errorsrW   r@   ellipse
sub_entitys           r9   r   r      s#     8Q
C!#F (;;%999MM% GG22J3v;-X
 ff%MM% '''5Ga X 67MM% $nn. (
j&1!+!6!6!8J$$Q'()(2 IIfJr8   c                p    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_entitiesrp   r   _transform_clones)ri   rj   rk   cloness       r9   r    r       s9     (CHc*F!X"61c2;r8   c                    g }| D ]7  }|j                   s	 |j                  t              }|j                  |       9 |S # t        $ r0 |j                  t        j                  t        |       d|       Y tw xY w)N)copy_strategyz entity does not support copy)	re   copyr   rT   r   rU   r   r3   r>   )ri   rk   ry   r@   clones        r9   rw   rw      s     F !		!KKlK;E MM% ! M   	GG((v;-<=	s   A6A:9A:c           	        g }| D ]%  }	 |j                  |       |j                  |       ' |S # t        t        f$ r0 |j	                  t
        j                  t        |       d|       Y ht        $ r0 |j	                  t
        j                  t        |       d|       Y t        $ r] 	 |j                  t        ||             n<# t        $ r0 |j	                  t
        j                  t        |       d|       Y nw xY wY w xY w)Nrb   rd   rc   )rf   rT   rg   rh   rU   r   r2   r>   r   r5   r   extend_scale_non_uniform	TypeErrorr4   )ry   rj   rk   ri   r@   s        r9   rx   rx      s    "H $	$Q. OOF#3$6 O1  34 	GG22v;-FG
 ) 	GG11v;-bc
 & 	 261 => 336{m#OP	s?   /<D	-5D	$D	-C	D		6D?D	DD	D	c              #  X  K   t        | t              r+t        j                  |       }|j	                  |       | y t        | t
        t        f      rP| j                         D ]<  }t        |t              rt        j                  |      }|j	                  |       | > y t        wrD   )	rp   r   r   from_arcrf   r   r   virtual_entitiesr   )r@   rj   ru   s      r9   r   r      s     &&!%%f-
Q	FZ2	3 113 	J*f-$--j9
  #		 s   B(B*c                    t        |      }|r@t        | t        j                  |j                  |j
                  |j                              S t               S )z=Translates (moves) `entities` inplace by the `offset` vector.rj   )r   rl   r   r!   xyzr   )ri   offsetvs      r9   r!   r!     s=    VAH$6$6qssACC$EFF8Or8   c                    t        |      }t        |      t        kD  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   )floatabsMIN_SCALING_FACTORrl   r   r#   r   )ri   factorfs      r9   r"   r"     s;    
 	fA
1v""HNN1a$;<<8Or8   c           
     p    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

    c                D    t        |       } t        |       t        kD  r| S dS )Ng      ?)r   r   r   )r   s    r9   safezscale.<locals>.safe+  s"    !HF//q8S8r8   )r   r   r^   r   )r   r   r#   )ri   sxsyszr   s        r9   r#   r#   !  s/    9 8X^^DHd2hRIJJr8   c                p    t        |      }|r t        | t        j                  |            S t	               S zBRotates `entities` inplace by `angle` in radians about the x-axis.r   )r   rl   r   r$   r   ri   angleas      r9   r$   r$   2  -    eAH$5$5a$8998Or8   c                p    t        |      }|r t        | t        j                  |            S t	               S )zBRotates `entities` inplace by `angle` in radians about the y-axis.r   )r   rl   r   r%   r   r   s      r9   r%   r%   :  r   r8   c                p    t        |      }|r t        | t        j                  |            S t	               S r   )r   rl   r   r&   r   r   s      r9   r&   r&   B  r   r8   c                    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_nullrl   r   r'   )ri   axisr   r   r   s        r9   r'   r'   J  sH     	eAxT
A99H$8$8A$>??8Or8   c                     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@   rj   s     r9   r(   r(   X  s     "6(A.d::r8   c                ,    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)ri   rj   s     r9   r)   r)   _  s     "$x.!44r8   c                   t        |       dk(  ry | d   }t        |      sy |j                  }|y |j                         }|y |j                  j                         }|j                  |j                  d      }	 |j                  |       | D ]   }t        |      s|j                  ||       " |S # t        $ rP t        j                  d       |j                  |       |j                  j                  |j                  d       Y y w xY w)Nr   )r   r   r   z#cannot apply invalid transformationF)r   )rQ   r   doc
get_layoutblocksnew_anonymous_blockadd_blockrefnamerf   r   loggerwarningdelete_entitydelete_blockmove_to_layout)ri   rj   first_entityr   layoutblockinsertes           r9   r   r   h  s    8}A;L\*


C
{$$&F~JJ**,E  Y7F  ,Q!!!U+, L % <>V$



7	s   :B2 2AD
Dc                v    | D ]4  }t        |t              s|j                         }|j                  |       6 y rD   )rp   r   temporary_transformationapply_transformation)ri   r@   tts      r9   apply_temporary_transformationsr     s8     ,f=>002B##F+,r8   )ri   Iterable[DXFEntity]rj   r   r^   r   rD   )ri   r   rj   zOptional[Matrix44]r^   zTuple[Logger, List[DXFEntity]])ri   r   rk   r   r^   zlist[DXFEntity])ry   r   rj   r   rk   r   )r@   r   rj   r   )ri   r   r   r   r^   r   )ri   r   r   r   r^   r   )
ri   r   r   r   r   r   r   r   r^   r   )ri   r   r   r   r^   r   )ri   r   r   r   r   r   r^   r   )r@   r   rj   r   r^   bool)ri   r   rj   r   r^   BlockLayout | None)ri   zSequence[DXFEntity]rj   r   r^   r   )ri   r   r^   r_   )<
__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   rl   r   r    rw   rx   r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r   r   r7   r8   r9   <module>r      sI   #	 	 	      ? ; ")  			7	#/DII /! !H!H,!,, ,` <@!&8#"$@ K";5!5&.55!&.D,r8   