
    OgT                    @   d dl mZ d dl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 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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'm(Z( d dl)m*Z* erd dl	m+Z+m,Z,m-Z-m.Z. g dZ/ G d dej`                        Z1 G d de1      Z2 G d de1      Z3 G d de1      Z4 G d de1      Z5 G d de3      Z6 G d de1      Z7 G d de3      Z8 G d d e3      Z9 G d! d"e3      Z: G d# d$e3      Z;d%Z<d&Z= G d' d(e3      Z> G d) d*e3      Z?dId+Z@ G d, d-e3      ZA G d. d/e3      ZBi d0e9d1e4d2e>d3e>d4e4d5e4d6e;d7e;d8e4d9eAd:e5d;e6d<e8d=e?d>e7d?e:d@e4e9e>e9eBeAdAZC	 dJ	 	 	 dKdBZDdLdCZE	 dJ	 	 	 	 	 dMdDZFdNdEZGdOdFZHdPdGZIdNdHZJy)Q    )annotations)IterableOptionalcastTYPE_CHECKINGN)	DXFEntityInsertget_font_name)const)TextEntityAlignment)Vec3UCSZ_AXISX_AXISBoundingBox)Path	make_pathfrom_verticesprecise_bbox)MeshBuilderMeshVertexMergerTraceBuilder)SupportsVirtualEntitiesvirtual_entities)TextLineunified_alignment
plain_text	text_wrapestimate_mtext_content_extents)fonts)
LWPolylinePolylineMTextText)make_primitiverecursive_decomposeto_primitivesto_verticesto_control_verticesto_paths	to_meshesc                      e Zd ZU dZdZded<   	 d	 	 	 ddZedd       Zedd       Z	edd	       Z
ej                  dd
       ZdddZy)	Primitivea  It is not efficient to create the Path() or MeshBuilder() representation
    by default. For some entities it's just not needed (LINE, POINT) and for
    others the builtin flattening() method is more efficient or accurate than
    using a Path() proxy object. (ARC, CIRCLE, ELLIPSE, SPLINE).

    The `max_flattening_distance` defines the max distance between the
    approximation line and the original curve. Use argument
    `max_flattening_distance` to override the default value, or set the value
    by direct attribute access.

    g{Gz?floatmax_flattening_distanceNc                B    || _         d | _        d | _        ||| _        y y N)entity_path_meshr/   )selfr2   r/   s      V/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/disassemble.py__init__zPrimitive.__init__6   s.     "(%)
 -1
".+BD( /    c                z    | j                   r"t        | j                   j                        dk(  S | j                  du S )zbReturns `True` if represents an empty primitive which do not
        yield any vertices.

        r   N)r4   lenverticespathr5   s    r6   is_emptyzPrimitive.is_emptyB   s4     ::tzz**+q00yyD  r8   c                     y)z:class:`~ezdxf.path.Path` representation or ``None``,
        idiom to check if is a path representation (could be empty)::

            if primitive.path is not None:
                process(primitive.path)

        N r=   s    r6   r<   zPrimitive.pathL        r8   c                     y)z:class:`~ezdxf.render.mesh.MeshBuilder` representation or ``None``,
        idiom to check if is a mesh representation (could be empty)::

            if primitive.mesh is not None:
                process(primitive.mesh)

        Nr@   r=   s    r6   meshzPrimitive.meshW   rA   r8   c                     y)zkYields all vertices of the path/mesh representation as
        :class:`~ezdxf.math.Vec3` objects.

        Nr@   r=   s    r6   r;   zPrimitive.verticesb   s     	r8   c                    | j                   rt        | j                               S | j                  }|r&|rt        |j	                               S t        |      S t               S )u  Returns the :class:`~ezdxf.math.BoundingBox` of the path/mesh
        representation. Returns the precise bounding box for the path
        representation if `fast` is ``False``, otherwise the bounding box for
        Bézier curves is based on their control points.

        )rC   r   r;   r<   control_verticesr   )r5   fastr<   s      r6   bboxzPrimitive.bboxj   sR     99t}}//yy"4#8#8#:;;%%}r8   r1   )r2   r   r/   Optional[float]returnboolrK   zOptional[Path]rK   zOptional[MeshBuilder]rK   Iterable[Vec3]FrK   r   )__name__
__module____qualname____doc__r/   __annotations__r7   propertyr>   r<   rC   abcabstractmethodr;   rH   r@   r8   r6   r-   r-   '   s    
 &*U) MQ
C
C:I
C ! !     	 r8   r-   c                  &    e Zd Zedd       ZddZy)EmptyPrimitivec                     y)NTr@   r=   s    r6   r>   zEmptyPrimitive.is_empty|   s    r8   c                    g S r1   r@   r=   s    r6   r;   zEmptyPrimitive.vertices   s    	r8   NrJ   rO   )rS   rT   rU   rX   r>   r;   r@   r8   r6   r\   r\   {   s     r8   r\   c                  t     e Zd ZdZd fdZej                  d        Zedd       Z	ed	d       Z
d
dZ xZS )ConvertedPrimitivezdBase class for all DXF entities which store the path/mesh representation
    at instantiation.

    c                D    t         |   |       | j                          y r1   )superr7   _convert_entity)r5   r2   	__class__s     r6   r7   zConvertedPrimitive.__init__   s     r8   c                     y)z1This method creates the path/mesh representation.Nr@   r=   s    r6   rc   z"ConvertedPrimitive._convert_entity   s     	r8   c                    | j                   S r1   )r3   r=   s    r6   r<   zConvertedPrimitive.path       zzr8   c                    | j                   S r1   )r4   r=   s    r6   rC   zConvertedPrimitive.mesh   rg   r8   c              #     K   | j                   r.| j                  j                  | j                        E d {    y | j                  r| j
                  j                  E d {    y y 7 17 wr1   )r<   r3   
flatteningr/   rC   r4   r;   r=   s    r6   r;   zConvertedPrimitive.vertices   sT     99zz,,T-I-IJJJYYzz****  K*s!   5A-A)*A-"A+#A-+A-)r2   r   rM   rN   rO   )rS   rT   rU   rV   r7   rY   rZ   rc   rX   r<   rC   r;   __classcell__)rd   s   @r6   r`   r`      sT    
 	     +r8   r`   c                  &    e Zd Zedd       ZddZy)CurvePrimitivec                f    | j                   t        | j                        | _         | j                   S z%Create path representation on demand.r3   r   r2   r=   s    r6   r<   zCurvePrimitive.path   (     ::"4;;/DJzzr8   c              #  j   K   | j                   j                  | j                        E d {    y 7 wr1   )r2   rj   r/   r=   s    r6   r;   zCurvePrimitive.vertices   s&     
 ;;))$*F*FGGGs   )313NrM   rO   )rS   rT   rU   rX   r<   r;   r@   r8   r6   rm   rm      s     Hr8   rm   c                  0    e Zd Zedd       ZddZdddZy)	LinePrimitivec                f    | j                   t        | j                        | _         | j                   S ro   rp   r=   s    r6   r<   zLinePrimitive.path   rq   r8   c              #     K   | j                   }|j                  j                   |j                  j                   y wr1   )r2   dxfstartend)r5   es     r6   r;   zLinePrimitive.vertices   s*     KKeekkeeiis   >A c                    | j                   }t        |j                  j                  |j                  j                  f      S r1   )r2   r   rw   rx   ry   )r5   rG   rz   s      r6   rH   zLinePrimitive.bbox   s+    KKAEEKK344r8   NrM   rO   rQ   rR   rS   rT   rU   rX   r<   r;   rH   r@   r8   r6   rt   rt      s     
5r8   rt   c                      e Zd ZddZy)LwPolylinePrimitivec                x   t        d| j                        }|j                  r|j                         }|j                  j
                  }t        j                  |      }t               }|j                  ||      D ]  }|j                  |        t        j                  |      | _        y t        |      | _        y )Nr!   )r   r2   	has_widthocsrw   	elevationr   from_polyliner   	faces_wcsadd_facer   from_builderr4   r   r3   )r5   rz   r   r   tbmbfaces          r6   rc   z#LwPolylinePrimitive._convert_entity   s    \4;;7;;%%'CI++A.B!#BS)4 "D!"$11"5DJ"1DJr8   NrK   NonerS   rT   rU   rc   r@   r8   r6   r~   r~      s    &r8   r~   c                  0    e Zd Zedd       ZddZdddZy)	PointPrimitivec                    | j                   .t        | j                  j                  j                        | _         | j                   S )zCreate path representation on demand.

        :class:`Path` can not represent a point, a :class:`Path` with only a
        start point yields not vertices!

        )r3   r   r2   rw   locationr=   s    r6   r<   zPointPrimitive.path   s2     ::dkkoo667DJzzr8   c              #  P   K   | j                   j                  j                   y wr1   )r2   rw   r   r=   s    r6   r;   zPointPrimitive.vertices   s     kkoo&&&s   $&c                V    t        | j                  j                  j                  f      S r1   )r   r2   rw   r   )r5   rG   s     r6   rH   zPointPrimitive.bbox   s    DKKOO44677r8   NrM   rO   rQ   rR   r|   r@   r8   r6   r   r      s    	 	'8r8   r   c                      e Zd Zd Zy)MeshPrimitivec                L    t        j                  | j                        | _        y r1   )r   	from_meshr2   r4   r=   s    r6   rc   zMeshPrimitive._convert_entity   s     **4;;7
r8   Nr   r@   r8   r6   r   r      s    8r8   r   c                      e Zd Zd Zy)QuadrilateralPrimitivec                8    t        | j                        | _        y r1   r   r2   r3   r=   s    r6   rc   z&QuadrilateralPrimitive._convert_entity       t{{+
r8   Nr   r@   r8   r6   r   r      s    ,r8   r   c                      e Zd ZddZy)PolylinePrimitivec                4   t        d| j                        }|j                  r|j                  r|j	                         }|j
                  j                  j                  }t        j                  |      }t               }|j                  ||      D ]  }|j                  |        t        j                  |      | _        y |j                  s|j                   rt#        |      | _        y t        j&                  |      }t        j                  |      | _        y )Nr"   )r   r2   is_2d_polyliner   r   rw   r   zr   r   r   r   r   r   r   r4   is_3d_polyliner   r3   from_polyface)r5   rz   r   r   r   r   r   ms           r6   rc   z!PolylinePrimitive._convert_entity   s    :t{{3%%'C))I++A.B!#BS)4 "D!"$11"5DJ!1!1"1DJ ..q1A$11!4DJr8   Nr   r   r@   r8   r6   r   r      s    5r8   r   c                      e Zd Zd Zy)HatchPrimitivec                8    t        | j                        | _        y r1   r   r=   s    r6   rc   zHatchPrimitive._convert_entity
  r   r8   Nr   r@   r8   r6   r   r   	      ,r8   r   gZd;O?gZd;O?c                      e Zd ZddZy)TextLinePrimitivec                   fd}fd}t        d| j                        j                         dk(  rj                  j                  }nj                  j
                  }t        |      }t        |      dk(  rt               | _	        yt        j                  t              j                  j                  j                  j                        }t        ||      }j!                         \  }|t"        j$                  k(  xs |t"        j&                  k(  j                  j(                  dkD  r|j+                  |       t-              \  }}j.                  rdnd	}	j0                  rdnd	}
t3        j4                  j                  j6                        }|j9                   |       || |       |	|
f|
      }j;                         }t=        |j?                  |      d      | _	        y)zCalculates the rough border path for a single line text.

        Calculation is based on a monospaced font and therefore the border
        path is just an educated guess.

        Vertical text generation and oblique angle is ignored.

        c                      r j                        sz
  j                  S t        j                  j                  j
                        S r1   )iscloseanglemathradiansrw   rotation)fit_or_alignedp1p2texts   r6   text_rotationz8TextLinePrimitive._convert_entity.<locals>.text_rotation  s7    bjjnR&||DHH$5$566r8   c                 2     rj                  d      S S )N      ?)factor)lerp)r   r   r   s   r6   r   z3TextLinePrimitive._convert_entity.<locals>.location#  s    wwr#w..Ir8   r$   ATTDEFr   N      )r   scaleobliqueTclose) r   r2   dxftyperw   tagr   r   r:   r   r3   r    	make_fontr
   heightwidthr   get_placementr   FITALIGNEDhalignstretchr   is_backwardis_upside_downr   r   r   corner_verticesr   r   points_to_wcs)r5   r   r   contentfont	text_line	alignmentr   valignmirror_xmirror_yr   r   r   r   r   r   r   s                 @@@@r6   rc   z!TextLinePrimitive._convert_entity  s   	7	
 FDKK(<<>X%hhllGhhmmGW%w<1DJ$$((..
 Wd+	 ..0	2r:B,000 8/777 	 88??QiR0*40))2q,,2!dhh&6&67#33J/X& 4 
 hhj"o.

r8   Nr   r   r@   r8   r6   r   r     s    @
r8   r   c                      e Zd ZddZy)MTextPrimitivec                  	
 d	fd}dfd
d	
fdd	fddfd}fddfd}t        d| j                        j                  uj                  j	                  d
d      t        j                  t              j                  j                  d      	 |       t              dk(  rt               | _        y	 |       } |       }t        |j                  |      d      | _        y	)zCalculates the rough border path for a MTEXT entity.

        Calculation is based on a mono-spaced font and therefore the border
        path is just an educated guess.

        Most special features of MTEXT is not supported.

        c                 V    j                  d      } t        | j                        S )NF)split)r   r   
text_width)r   	box_widthr   mtexts    r6   get_contentz3MTextPrimitive._convert_entity.<locals>.get_contenta  s)    ##%#0DT9doo>>r8   c                      t         d       S )Nc                    t        |       S r1   r:   )ss    r6   <lambda>zEMTextPrimitive._convert_entity.<locals>.get_max_str.<locals>.<lambda>f  s
    c!f r8   key)max)r   s   r6   get_max_strz3MTextPrimitive._convert_entity.<locals>.get_max_stre  s    w$455r8   c                 \    rS         } t        |       dk(  rd} j                  |       S )Nr    )r:   r   )r   r   r   r   s    r6   get_rect_widthz6MTextPrimitive._convert_entity.<locals>.get_rect_widthh  s2      A1v{??1%%r8   c                     j                   j                  } j                   j                  }|j                  j                  z  dz  }|| z
  }t              }| |z  ||dz
  z  z   S )NgQ?r   )measurementstotal_height
cap_heightrw   line_spacing_factorr:   )line_heightr   line_spacingspacing
line_countr   r   r   s        r6   get_rect_heightz7MTextPrimitive._convert_entity.<locals>.get_rect_heightp  sl    ++88K**55J &		(E(EELL"[0GWJ+ga.HHHr8   c                 |   j                   j                  } j                   j                  }t        }j                   j	                  d      rj                   j
                  }nJj                   j	                  d      r/t        j                  j                   j                        }t        }t        | ||      S )a  Create local coordinate system:
            origin = insertion point
            z-axis = extrusion vector
            x-axis = text_direction or text rotation, text rotation requires
                extrusion vector == (0, 0, 1) or treatment like an OCS?

            text_directionr   )originuxuz)rw   insert	extrusionr   hasattrr   r   from_deg_angler   r   r   )r   z_axisx_axisr   s      r6   get_ucsz/MTextPrimitive._convert_entity.<locals>.get_ucs~  s     YY%%FYY((FFyy  !1211"":.,,UYY-?-?@fF;;r8   c                     t              \  } }d}d}| t        j                  k(  rd}n| t        j                  k(  rd}|t        j                  k(  rd}||fS |t        j
                  k(  rd}||fS )Nr   g      g      r         ?)r   r   CENTERRIGHTMIDDLEBOTTOM)r   r   shift_xshift_yr   s       r6   get_shift_factorsz9MTextPrimitive._convert_entity.<locals>.get_shift_factors  sy    .u5NFFGG%5;;&% G## 5<<'G##r8   c                    r?j                   } j                  }| dk(  s|dk(  r_t              \  }}| dk(  r|} |dk(  rE|}nBj                  j	                  d 
             } j                  j	                  d 	             }t        dd      t        | d      t        | |       t        d|       g}        \  }}t        || z  ||z        fd|D        S )zsCreate corner vertices in the local working plan, where
            the insertion point is the origin.
            g        
rect_widthrect_heightr   c              3  (   K   | ]	  }|z     y wr1   r@   ).0vshifts     r6   	<genexpr>zNMTextPrimitive._convert_entity.<locals>.get_corner_vertices.<locals>.<genexpr>  s     0!AI0s   )total_widthr   _estimate_column_extentsrw   getr   )r  r  whr;   sxsyr  columnsr   r   r
  r   s          @r6   get_corner_verticesz;MTextPrimitive._convert_entity.<locals>.get_corner_vertices  s     $00
%22$s(: 4E:DAq!S(%&
"c)&'"YY]]<9IJ
#iimmM?;LM Q
Z#Z+.Q%	H '(FBj"{*:;E0x00r8   r#   Nr   r   r  Tr   )rK   z	list[str])rK   str)rK   r.   )rK   r   rO   )r   r2   r  rw   r  r    r   r
   char_heightr:   r   r3   r   r   )r5   r   r  r  ucsr   r   r  r   r   r   r   r   r
  r   s         @@@@@@@@@r6   rc   zMTextPrimitive._convert_entityW  s    	?	6	&	I	<&	$	1 	1: GT[[1--?		gq1I??e$eii&;&;SD "-G7|q !V
i-/"o.

r8   Nr   r   r@   r8   r6   r   r   V  s    v
r8   r   c                f   | j                   }|J | j                  }|j                  dkD  r-|j                  d      }t	        |      dkD  rt        |d       }t        |t        j                  | j                  j                  d      |j                  | j                  j                  d            S )Nr   z\Nc                    t        |       S r1   r   )ts    r6   r   z*_estimate_column_extents.<locals>.<lambda>  s
    3q6 r8   r   r  r   )r   r   column_widthr   )r  r   countr   r:   r   r   r    MonospaceFontrw   r  r   get_default)r   r  _content_columns_contents       r6   r  r    s    mmGzzH}}q#>>%0 1$+1ABH)  !6!6<]]!II112GH	 r8   c                      e Zd Zd Zy)ImagePrimitivec                8    t        | j                        | _        y r1   r   r=   s    r6   rc   zImagePrimitive._convert_entity  r   r8   Nr   r@   r8   r6   r)  r)    r   r8   r)  c                      e Zd Zd Zy)ViewportPrimitivec                p    | j                   }|j                  j                  dk(  ry t        |      | _        y )Nr   )r2   rw   statusr   r3   )r5   vps     r6   rc   z!ViewportPrimitive._convert_entity  s)    [[66==Ar]
r8   Nr   r@   r8   r6   r,  r,    s    #r8   r,  3DFACEARCATTRIBr   CIRCLEELLIPSEHATCHMPOLYGONHELIXIMAGELINE
LWPOLYLINEMESHMTEXTPOINTPOLYLINESPLINE)SOLIDTEXTTRACEVIEWPORTWIPEOUTc                x    t         j                  | j                         t              } ||       }|r||_        |S )a  Factory to create path/mesh primitives. The `max_flattening_distance`
    defines the max distance between the approximation line and the original
    curve. Use `max_flattening_distance` to override the default value.

    Returns an **empty primitive** for unsupported entities. The `empty` state
    of a primitive can be checked by the property :attr:`is_empty`.
    The :attr:`path` and the :attr:`mesh` attributes of an empty primitive
    are ``None`` and the :meth:`vertices` method  yields no vertices.

    )_PRIMITIVE_CLASSESr  r   r\   r/   )r2   r/   cls	primitives       r6   r%   r%   
  s7     
 
 !1>
BCFI,C	)r8   c              #  p  K   | D ]  }t        |t              rb|j                  dkD  r"t        |j	                               E d{    D|j
                  E d{    t        t        |            E d{    ut        |t              rt        t        |            E d{    |  y7 j7 W7 =7 w)a  Recursive decomposition of the given DXF entity collection into a flat
    stream of DXF entities. All block references (INSERT) and entities which provide
    a :meth:`virtual_entities` method will be disassembled into simple DXF
    sub-entities, therefore the returned entity stream does not contain any
    INSERT entity.

    Point entities will **not** be disassembled into DXF sub-entities,
    as defined by the current point style $PDMODE.

    These entity types include sub-entities and will be decomposed into
    simple DXF entities:

        - INSERT
        - DIMENSION
        - LEADER
        - MLEADER
        - MLINE

    Decomposition of XREF, UNDERLAY and ACAD_TABLE entities is not supported.

    This function does not apply the clipping path created by the XCLIP command. 
    The function returns all entities and ignores the clipping path polygon and no 
    entity is clipped.

    r   N)
isinstancer	   mcountr&   multi_insertattribsr   r   )entitiesr2   s     r6   r&   r&     s     4  ff%}}q .v/B/B/DEEE!>>))./?/GHHH 78*+;F+CDDDL F)H EsH   AB6B.B6B0B64B25,B6!B4"B60B62B64B6c              #  6   K   | D ]  }t        ||        yw)zYields all DXF entities as path or mesh primitives. Yields
    unsupported entities as empty primitives, see :func:`make_primitive`.

    Args:
        entities: iterable of DXF entities
        max_flattening_distance: override the default value

    N)r%   )rN  r/   rz   s      r6   r'   r'   H  s%       9Q 7889s   c              #  N   K   | D ]  }|j                         E d{     y7 w)zYields all vertices from the given `primitives`. Paths will be flattened
    to create the associated vertices. See also :func:`to_control_vertices` to
    collect only the control vertices from the paths without flattening.

    N)r;   )
primitivesps     r6   r(   r(   X  s)        ::< s   %#%c              #  P   K   | D ]  }|j                   |j                     yw)z~Yields all :class:`~ezdxf.path.Path` objects from the given
    `primitives`. Ignores primitives without a defined path.

    N)r<   rQ  prims     r6   r*   r*   b  *     
  99 ))O   &&c              #  P   K   | D ]  }|j                   |j                     yw)zYields all :class:`~ezdxf.render.MeshBuilder` objects from the given
    `primitives`. Ignores primitives without a defined mesh.

    N)rC   rT  s     r6   r+   r+   l  rV  rW  c              #     K   | D ]I  }|j                   r#|j                   j                         E d{    2|j                         E d{    K y7  7 	w)zYields all path control vertices and all mesh vertices from the given
    `primitives`. Like :func:`to_vertices`, but without flattening.

    N)r<   rF   r;   rT  s     r6   r)   r)   v  sL     
  '99yy11333}}&&' 4&s!   /AAA
AAA)r   r#   r1   )r2   r   rK   r-   )rN  Iterable[DXFEntity]rK   rZ  )rN  rZ  r/   rI   rK   Iterable[Primitive])rQ  r[  rK   rP   )rQ  r[  rK   zIterable[Path])rQ  r[  rK   zIterable[MeshBuilder])K
__future__r   typingr   r   r   r   rY   r   ezdxf.entitiesr   r	   r
   ezdxf.lldxfr   ezdxf.enumsr   
ezdxf.mathr   r   r   r   r   
ezdxf.pathr   r   r   r   ezdxf.renderr   r   r   ezdxf.protocolsr   r   ezdxf.tools.textr   r   r   r   r   ezdxf.fontsr    r!   r"   r#   r$   __all__ABCr-   r\   r`   rm   rt   r~   r   r   r   r   r   DESCENDER_FACTORX_HEIGHT_FACTORr   r   r  r)  r,  rF  r%   r&   r'   r(   r*   r+   r)   r@   r8   r6   <module>rk     sw   # : : 
  ; ;  + = = C C D D E  @@Q QhY + +<HY H 5I 5&&, &"8Y 8(8& 8
,/ ,5* 5(,' ,
  A
* A
Hw
' w
t ,' ,
#* #$	>
   n ~ ^  ^ ^ M % M  ^!" ^#$ !%& n'( $#!1 : 04('X 049!9,9 9  
'r8   