
    OgTH                       U 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 d dlZd dlZd dlmZ d dlmZmZmZ d dlmZmZ d dlmZ d d	lmZmZmZmZmZ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* d dl+m,Z, d dl-m.Z. d dl/m0Z0 d dl1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z: ddlm;Z; erd dl<m=Z=m>Z>m?Z?m@Z@ d dlAmBZB d dlCmDZD ddgZEeeFeFeFeFeFf   ZGdeHd<    eId      ZJdZKdZL ed  ed!ej                  d"#       ed$d d%&       ed'd d%&       ed(d )       ed*d d%&       ed+ej                  ed%ej                  e,      d-      ZP e eP      ZQe: G d. de7             ZR G d/ d0e,      ZSd3d4d1ZTd3d5d2ZUy)6    )annotations)TYPE_CHECKINGTupleSequenceIterableUnionIteratorOptional)	TypeAliasSelfN)contextmanager)Vec3Matrix44Z_AXIS)OCSTransformNonUniformScalingError)	validator)DXFAttrDXFAttributesDefSubclassXTypeRETURN_DEFAULTgroup_code_mapping)SUBCLASS_MARKERDXF2000LWPOLYLINE_CLOSEDDXFStructureError)Tags)DXFTag	DXFVertex)VertexArray)virtual_lwpolyline_entitiesexplode_entity)EntityQuery   )
base_classSubclassProcessor)
DXFGraphicacdb_entity)register_entity)default_copy)DXFNamespaceLineArc	DXFEntity)AbstractTagWriter)
BaseLayout
LWPolylineFORMAT_CODESr   LWPointTypexysebvxyseb)
      (   )   *   AcDbPolylineZ   __len__)xtypegetter&   T)defaultoptional'   F   rC   +      )r@   rC   rD   r   fixer)count	elevation	thicknessflagsconst_width	extrusionc                      e Zd ZdZdZ eeee      Z	e
Z fdZefd!dZ	 d"	 	 	 d# fdZd$dZd%dZd& fdZed'd	       Zej*                  d(d
       Zed'd       Zd)d*dZed'd       Zed'd       Zd+dZd,dZd-dZd.dZd/dZd0dZd1dZ d1dZ!e"fd2dZ#e"f	 	 	 	 	 	 	 d3dZ$e"f	 	 	 	 	 d4dZ%e&e"fd5d       Z'e"fd6dZ(e"f	 	 	 	 	 d4dZ)d7dZ*d8dZ+d9dZ,d"d:d Z- xZ.S );r3   zDXF LWPOLYLINE entity
LWPOLYLINEc                @    t         |           t               | _        y N)super__init__LWPolylinePointslwpoints)self	__class__s    ^/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/entities/lwpolyline.pyrV   zLWPolyline.__init__f   s    (*    c                p    t        |t              sJ t        j                  | j                        |_        y)zCopy lwpoints.N)
isinstancer3   copydeepcopyrX   )rY   entitycopy_strategys      r[   	copy_datazLWPolyline.copy_dataj   s&    &*-----6r\   c                    t         |   |      }|rX|j                  d      }|r,| j                  |      }|j	                  |t
        |d       |S t        d|j                   d      |S )z
        Adds subclass processing for AcDbPolyline, requires previous base class
        and AcDbEntity processing by parent class.
           T)subclassrecoverz/missing 'AcDbPolyline' subclass in LWPOLYLINE(#))rU   load_dxf_attribssubclass_by_indexload_verticesfast_load_dxfattribsacdb_lwpolyline_group_codesr   handle)rY   	processordxftagsrZ   s       r[   ri   zLWPolyline.load_dxf_attribso   s     g&y1..q1D))$/../! 	 /  
 (Ecjj\QRS  
r\   c                @    t         j                  |      \  | _        }|S rT   )rW   	from_tagsrX   )rY   rq   unprocessed_tagss      r[   rk   zLWPolyline.load_vertices   s     *:*D*DT*J''r\   c                2    t        | j                        dkD  S Nr   lenrX   )rY   	tagwriters     r[   preprocess_exportzLWPolyline.preprocess_export   s     4==!A%%r\   c                D   t         |   |       |j                  t        t        j
                         | j                  j                  |g d       |j                  t        | j                  j                                      | j                  j                  |d       y)z(Export entity specific data as DXF tags.)rK   rN   rO   rL   rM   rP   N)rU   export_entity
write_tag2r   acdb_lwpolylinenamerp   export_dxf_attribs
write_tagsr   rX   dxftags)rY   ry   rZ   s     r[   r|   zLWPolyline.export_entity   st    i(_o.B.BC##G	
 	T$--"7"7"9:;##I{;r\   c                ,    | j                  t              S )zGet/set closed state of polyline.  A closed polyline has a connection
        segment from the last vertex to the first vertex.
        get_flag_stater   rY   s    r[   closedzLWPolyline.closed       
 ""#455r\   c                0    | j                  t        |       y rT   )set_flag_stater   )rY   statuss     r[   r   zLWPolyline.closed   s    -v6r\   c                ,    | j                  t              S )z]Get closed state of LWPOLYLINE.
        Compatibility interface to :class:`Polyline`
        r   r   s    r[   	is_closedzLWPolyline.is_closed   r   r\   c                    || _         y)z]Set closed state of LWPOLYLINE.
        Compatibility interface to :class:`Polyline`
        N)r   )rY   states     r[   closezLWPolyline.close   s     r\   c                :    t        d | j                  D              S )z2Returns ``True`` if LWPOLYLINE has an arc segment.c              3  >   K   | ]  \  }}}}}t        |        y wrT   )bool.0xysebs         r[   	<genexpr>z%LWPolyline.has_arc.<locals>.<genexpr>   s     >}q!Q147>s   )anyrX   r   s    r[   has_arczLWPolyline.has_arc   s     >>>>r\   c                    | j                   j                  d      r| j                   j                  dk7  S t        d | j                  D              S )zReturns ``True`` if LWPOLYLINE has any segment with width attributes
        or the DXF attribute const_width is not 0.

        rO           c              3  4   K   | ]  \  }}}}}|xs |  y wrT    r   s         r[   r   z'LWPolyline.has_width.<locals>.<genexpr>   s      ?1aAAFF?s   )rp   hasattrrO   r   rX   r   s    r[   	has_widthzLWPolyline.has_width   sB     88M* 88''3..????r\   c                ,    t        | j                        S )z!Returns count of polyline points.rw   r   s    r[   r?   zLWPolyline.__len__   s    4==!!r\   c                ,    t        | j                        S )zAReturns iterable of tuples (x, y, start_width, end_width, bulge).)iterrX   r   s    r[   __iter__zLWPolyline.__iter__   s    DMM""r\   c                     | j                   |   S )a  Returns point at position `index` as (x, y, start_width, end_width,
        bulge) tuple. start_width, end_width and bulge is 0 if not present,
        supports extended slicing. Point format is fixed as "xyseb".

        All coordinates in :ref:`OCS`.

        rX   rY   indexs     r[   __getitem__zLWPolyline.__getitem__   s     }}U##r\   c                4    t        |      | j                  |<   y)a  
        Set point at position `index` as (x, y, [start_width, [end_width,
        [bulge]]]) tuple. If start_width or end_width is 0 or left off the
        default width value is used. If the bulge value is left off, bulge is 0
        by default (straight line).
        Does NOT support extend slicing. Point format is fixed as "xyseb".

        All coordinates in :ref:`OCS`.

        Args:
            index: point index
            value: point value as (x, y, [start_width, [end_width, [bulge]]]) tuple

        N)compile_arrayrX   )rY   r   values      r[   __setitem__zLWPolyline.__setitem__   s      -U3er\   c                    | j                   |= y)z<Delete point at position `index`, supports extended slicing.Nr   r   s     r[   __delitem__zLWPolyline.__delitem__   s    MM% r\   c              #  2   K   | D ]  }|d   |d   f  yw)z
        Returns iterable of all polyline points as (x, y) tuples in :ref:`OCS`
        (:attr:`dxf.elevation` is the z-axis value).

        r   r&   Nr   )rY   points     r[   verticeszLWPolyline.vertices   s*       	%E(E!H$$	%s   c              #     K   | j                         }| j                  dd      }| j                         D ]#  \  }}|j                  t	        |||             % yw)zGReturns iterable of all polyline points as Vec3(x, y, z) in :ref:`WCS`.rL   r   rG   N)ocsget_dxf_attribr   to_wcsr   )rY   r   rL   r   r   s        r[   vertices_in_wcszLWPolyline.vertices_in_wcs   sW     hhj''S'A	MMO 	4DAq**T!Q	233	4s   AAc              #     K   | j                  dd      }| j                         D ]  \  }}t        |||        yw)zGReturns iterable of all polyline points as Vec3(x, y, z) in :ref:`OCS`.rL   r   rG   N)r   r   r   )rY   rL   r   r   s       r[   vertices_in_ocszLWPolyline.vertices_in_ocs   sC     ''S'A	MMO 	(DAqq!Y''	(s   <>c                >    | j                   j                  ||       y)a%  Append `point` to polyline, `format` specifies a user defined
        point format.

        All coordinates in :ref:`OCS`.

        Args:
            point: (x, y, [start_width, [end_width, [bulge]]]) tuple
            format: format string, default is "xyseb", see: `format codes`_

        formatNrX   append)rY   r   r   s      r[   r   zLWPolyline.append  s     	U62r\   c                V    t        ||      }| j                  j                  ||       y)a1  Insert new point in front of positions `pos`, `format` specifies a
        user defined point format.

        All coordinates in :ref:`OCS`.

        Args:
            pos: insert position
            point: point data
            format: format string, default is "xyseb", see: `format codes`_

        r   N)r   rX   insert)rY   posr   r   datas        r[   r   zLWPolyline.insert  s$     U62S$'r\   c                L    |D ]  }| j                   j                  ||       ! y)a`  
        Append new `points` to polyline, `format` specifies a user defined
        point format.

        All coordinates in :ref:`OCS`.

        Args:
            points: iterable of point, point is (x, y, [start_width, [end_width,
                [bulge]]]) tuple
            format: format string, default is "xyseb", see: `format codes`_

        r   Nr   )rY   pointsr   r   s       r[   append_pointszLWPolyline.append_points  s*      	7EMM  v 6	7r\   c              #  ^   K   | j                  |      }| | j                  ||       yw)zContext manager for polyline points. Returns a standard Python list
        of points, according to the format string.

        All coordinates in :ref:`OCS`.

        Args:
            format: format string, see `format codes`_

        r   N)
get_points
set_points)rY   r   r   s      r[   r   zLWPolyline.points1  s-      /v.s   +-c                V    | j                   D cg c]  }t        ||       c}S c c}w )a'  Returns all points as list of tuples, format specifies a user
        defined point format.

        All points in :ref:`OCS` as (x, y) tuples (:attr:`dxf.elevation` is
        the z-axis value).

        Args:
            format: format string, default is "xyseb", see `format codes`_

        r   )rX   format_point)rY   r   ps      r[   r   zLWPolyline.get_points@  s#     9=F1Qv.FFFs   &c                ^    | j                   j                          | j                  ||       y)a(  Remove all points and append new `points`.

        All coordinates in :ref:`OCS`.

        Args:
            points: iterable of point, point is (x, y, [start_width, [end_width,
                [bulge]]]) tuple
            format: format string, default is "xyseb", see `format codes`_

        r   N)rX   clearr   )rY   r   r   s      r[   r   zLWPolyline.set_pointsM  s'     	6&1r\   c                8    | j                   j                          y)zRemove all points.N)rX   r   r   s    r[   r   zLWPolyline.clear]  s    r\   c                (   | j                   }t        | j                   j                  |      j                  s| j                  rt        d      t        fd| j                         D              }g }t        || j                        D ]Y  \  }}|\  }}}}	}
j                  |      }j                  |	      }	|j                  |j                  |j                  ||	|
f       [ | j                  |       |r|d   j                  |_        |j#                  d      r j                  |j$                        |_        |j#                  d      r j'                  |j(                        |_        j*                  |_        | j-                  |       | S )a  Transform the LWPOLYLINE entity by transformation matrix `m` inplace.

        A non-uniform scaling is not supported if the entity contains circular
        arc segments (bulges).

        Args:
            m: transformation :class:`~ezdxf.math.Matrix44`

        Raises:
            NonUniformScalingError: for non-uniform scaling of entity containing
                circular arc segments (bulges)

        zHLWPOLYLINE containing arcs (bulges) does not support non uniform scalingc              3  @   K   | ]  }j                  |        y wrT   )transform_vertex)r   vr   s     r[   r   z'LWPolyline.transform.<locals>.<genexpr>w  s     PA,,Q/Ps   r   rO   rM   )rp   r   rP   scale_uniformr   r   listr   ziprX   transform_widthr   r   r   r   zrL   r   rO   transform_thicknessrM   new_extrusionpost_transform)rY   mrp   r   rX   r   r   _start_width	end_widthbulger   s              @r[   	transformzLWPolyline.transforma  sX    hh488--q1  T\\(Z 
 P9M9M9OPP$--0 	GDAq23/Aq+y%--k:K++I6IOOQSS!##{IuEF	G 	! $QKMMCM;;}%!11#//BCO;;{#33CMMBCM))Ar\   c              #  V   K   t        |       D ]  }|j                  |        |  yw)a   Yields the graphical representation of LWPOLYLINE as virtual DXF
        primitives (LINE or ARC).

        These virtual entities are located at the original location, but are not
        stored in the entity database, have no handle and are not assigned to
        any layout.

        N)r"   set_source_of_copy)rY   r   s     r[   virtual_entitieszLWPolyline.virtual_entities  s/      -T2 	A  &G	s   ')c                    t        | |      S )a  Explode the LWPOLYLINE entity as DXF primitives (LINE or ARC) into
        the target layout, if the target layout is ``None``, the target layout
        is the layout of the source entity. This method destroys the source entity.

        Returns an :class:`~ezdxf.query.EntityQuery` container referencing all DXF
        primitives.

        Args:
            target_layout: target layout for the DXF primitives, ``None`` for
                same layout as the source entity.

        r#   )rY   target_layouts     r[   explodezLWPolyline.explode  s     dM22r\   )ra   r   returnNonerT   )ro   zOptional[SubclassProcessor]r   r-   )rq   r   r   r   )ry   r1   r   r   )ry   r1   r   r   )r   r   )r   r   r   r   )T)r   r   r   r   )r   int)r   zIterator[LWPointType])r   r   r   r5   )r   r   r   Sequence[float]r   r   )r   r   r   r   )r   zIterator[tuple[float, float]])r   zIterator[Vec3]r   r   r   strr   r   )r   r   r   r   r   r   r   r   )r   zIterable[Sequence[float]]r   r   r   r   )r   r   r   zIterator[list[Sequence[float]]])r   r   r   zlist[Sequence[float]])r   r   )r   r   r   r3   )r   zIterator[Union[Line, Arc]])r   zOptional[BaseLayout]r   r%   )/__name__
__module____qualname____doc__DXFTYPEr   r'   r*   r~   
DXFATTRIBSr   MIN_DXF_VERSION_FOR_EXPORTrV   r,   rc   ri   rk   rz   r|   propertyr   setterr   r   r   r   r?   r   r   r   r   r   r   r   DEFAULT_FORMATr   r   r   r   r   r   r   r   r   r   r   __classcell__rZ   s   @r[   r3   r3   ^   s   Gz;HJ!(+ 5A 7 8<4	0 &
	< 6 6 ]]7 7 6 6 ? ? 	@ 	@"#$4"!%4( <J 3 ?M((.(8;(	($ @N7/79<7	7$ #1 / / (6 G @N2/29<2	2 ,\3 3r\   c                  V     e Zd ZdZdZdZdZdZdZe	d
d       Z
efd fdZdd	Z xZS )rW   )valuesr8   r:   r;   r<      c                    d fd}t               }g }d}i |D ]  }|j                  t        v r]|j                  dk(  r4||j                   ||             t	        |j
                  dd       }i X|j
                  |j                  <   r|j                  |        ||j                   ||               |      |fS )zSetup point array from tags.c                
   | j                  j                  j                  d             | j                  j                  j                  d             | j                  j                  j                  d             | S rv   )r   getSTART_WIDTH_CODEEND_WIDTH_CODE
BULGE_CODE)r   attribsclss    r[   build_vertexz0LWPolylinePoints.from_tags.<locals>.build_vertex  s]    LLS%9%91=>LLS%7%7;<LLS^^Q78Lr\   Nr8   r   re   )r   )r   list[float]r   r  )r   codeLWPOINTCODESr   r   r   )r  rq   r  rt   r   r   tagr  s   `      @r[   rs   zLWPolylinePoints.from_tags  s    	  6)+$(#% 	-Cxx<'88r>( U(;< 1Q0E G(+		GCHH% '',	- OOL/0!#333r\   c                :    t         |   t        ||             y )Nr   )rU   r   r   )rY   r   r   rZ   s      r[   r   zLWPolylinePoints.append  s    }U6:;r\   c              #     K   | D ]s  }|\  }}}}}t        | j                  ||f       |s|r0t        | j                  |       t        | j                  |       |s\t        | j
                  |       u y wrT   )r    VERTEX_CODEr   r  r  r  )rY   r   r   r   r   r   r   s          r[   r   zLWPolylinePoints.dxftags  s}      		5E27/Aq+y%D,,q!f55i T22K@@T00)<<T__e44		5s   AA<!A<)rq   zIterable[DXFTag]r   ztuple[Self, Tags]r   )r   zIterator[DXFTag])r   r   r   	__slots__r  r  r  r  VERTEX_SIZEclassmethodrs   r   r   r   r   r   s   @r[   rW   rW     sD    IKNJK4 4: <J <
5r\   rW   c                t    | \  }}}}}||f}t               t        fd|j                         D              S )a  Reformat point components.

    Format codes:

        - ``x`` = x-coordinate
        - ``y`` = y-coordinate
        - ``s`` = start width
        - ``e`` = end width
        - ``b`` = bulge value
        - ``v`` = (x, y) as tuple

    Args:
        point: list or tuple of (x, y, start_width, end_width, bulge)
        format: format string, default is "xyseb"

    Returns:
        Sequence[float]: tuple of selected components

    c              3  :   K   | ]  }|t         v s|     y wrT   )r4   )r   r	  varss     r[   r   zformat_point.<locals>.<genexpr>  s     O$,:NdOs   
)localstuplelower)	r   r   r   r   r   r   r   r   r  s	           @r[   r   r     s;    ( MAq!Q	
AA8DOOOOr\   c                H   t        j                   dd      }|j                         D cg c]  }|t        v s| }}t        ||       D ]Q  \  }}|t        vr|dk(  r*t	        |      }|j
                  |d<   |j                  |d<   >||dj                  |      <   S |S c c}w )a  Gather point components from input data.

    Format codes:

        - ``x`` = x-coordinate
        - ``y`` = y-coordinate
        - ``s`` = start width
        - ``e`` = end width
        - ``b`` = bulge value
        - ``v`` = (x, y [,z]) tuple (z-axis is ignored)

    Args:
        data: list or tuple of point components
        format: format string, default is "xyseb"

    Returns:
        array.array: array.array('d', (x, y, start_width, end_width, bulge))

    d)r   r   r   r   r   r   r   r&   r7   )arrayr  r4   r   r   r   r   r   )r   r   ar	  r   vertexs         r[   r   r     s    ( 	C23A%||~Ft1EdFFF64( +e|#3;%[F88AaD88AaD%*AgmmD!"+ H Gs
   BB)r7   )r   r   r   r   r   r   )r   r   r   zarray.array)V
__future__r   typingr   r   r   r   r   r	   r
   typing_extensionsr   r   r  r_   
contextlibr   
ezdxf.mathr   r   r   ezdxf.math.transformtoolsr   r   ezdxf.lldxfr   ezdxf.lldxf.attributesr   r   r   r   r   r   ezdxf.lldxf.constr   r   r   r   ezdxf.lldxf.tagsr   ezdxf.lldxf.typesr   r    ezdxf.lldxf.packedtagsr!   ezdxf.render.polyliner"   ezdxf.exploder$   ezdxf.queryr%   	dxfentityr'   r(   dxfgfxr)   r*   factoryr+   r,   ezdxf.entitiesr-   r.   r/   r0   ezdxf.lldxf.tagwriterr1   ezdxf.layoutsr2   __all__floatr5   __annotations__	frozensetr4   r   r
  callbackpoint3dis_not_null_vectorr~   rm   r3   rW   r   r   r   r\   r[   <module>r9     sn   #   .   % - - J !   " / . = ( # 4 + $ AA7(
(ueUE5@AY A"#
  5>>)DRT:RT: Q' r1t<--22 
< 1A  J3 J3 J3Z
35{ 35lP4r\   