Ë
    £èh·8  ã                  ó   — d dl mZ d dlZd dlmZmZ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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 erd dlm Z m!Z!m"Z"m#Z#m$Z$ d dl%m&Z& d dl'm(Z(  ejR                  d«      Z*g d¢Z+d„ Z,dedœ	 	 	 	 	 dd„Z-h d£Z.dd„Z/ddedœ	 	 	 	 	 dd„Z0dhZ1	 d	 	 	 	 	 d d„Z2	 	 	 	 d!d„Z3	 	 	 	 	 	 	 	 d"d„Z4y)#é    )ÚannotationsN)ÚTYPE_CHECKINGÚIterableÚCallableÚOptionalÚcast)Úconst)Úfactory)ÚPolylinePathÚEdgePathÚLineEdgeÚArcEdgeÚEllipseEdgeÚ
SplineEdge)ÚOCSÚVec3ÚABS_TOL)ÚNonUniformScalingErrorÚInsertTransformationError)ÚEntityQuery)Údefault_copyÚCopyNotSupported)Ú
DXFGraphicÚInsertÚAttribÚTextÚ	Dimension)Ú
DXFPolygon)Ú
BaseLayoutÚezdxf)Ú virtual_block_reference_entitiesÚvirtual_boundary_path_entitiesÚexplode_block_referenceÚexplode_entityÚattrib_to_textc                óN   — t         j                  dt        | «      › d|› d�«       y )Nz,(Virtual Block Reference Entities) Ignoring z: "Ú")ÚloggerÚdebugÚstr)ÚentityÚreasons     ú-lib/python3.12/site-packages/ezdxf/explode.pyÚdefault_logging_callbackr.   4   s$   € Ü
‡L�LØ
6´s¸6³{°mÀ3ÀvÀhÈaÐPõó    F©Úredraw_orderÚcopy_strategyc               óÊ  ‡‡‡‡— ‰€t        j                  d«      ‚| j                  €t        j                  d«      ‚ˆˆˆˆfd„}| j                  j                  }|€J d«       ‚g Š| j                  dkD  r| j                  «       D ]
  } ||«       Œ n || «       | j                  «       }|�|j                  | «       t        ‰«      S |j                  | «       t        ‰«      S )aG  Explode a block reference into DXF primitives.

    Transforms the block entities into the required WCS location by applying the
    block reference attributes `insert`, `extrusion`, `rotation` and the scaling
    values `xscale`, `yscale` and `zscale`.

    Returns an EntityQuery() container with all exploded DXF entities.

    Attached ATTRIB entities are converted to TEXT entities, this is the
    behavior of the BURST command of the AutoCAD Express Tools.

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

    Args:
        block_ref: Block reference entity (INSERT)
        target_layout: explicit target layout for exploded DXF entities
        redraw_order: create entities in ascending redraw order if ``True``
        copy_strategy: customizable copy strategy

    .. warning::

        **Non uniform scaling** may lead to incorrect results for text entities
        (TEXT, MTEXT, ATTRIB) and maybe some other entities.

    (internal API)

    zTarget layout is None.z5Block reference has to be assigned to a DXF document.c                óJ  •— t        | ‰‰¬«      D ]S  }|j                  «       }‰j                  |«       |dk(  rt        d|«      j	                  «        ‰j                  |«       ŒU | j                  D ]/  }t        |«      }‰j                  |«       ‰j                  |«       Œ1 y )Nr0   Ú	DIMENSIONr   )r!   ÚdxftypeÚ
add_entityr   ÚrenderÚappendÚattribsr%   )	Ú	block_refr+   r6   ÚattribÚtextr2   Úentitiesr1   Útarget_layouts	        €€€€r-   Ú_explode_single_block_refz:explode_block_reference.<locals>._explode_single_block_reff   s”   ø€ Ü6Ø LÀ÷
ˆFð —n‘nÓ&ˆGØ×$Ñ$ VÔ,Ø˜+Ò%ô �[ &Ó)×0Ñ0Ô2Ø�O‰O˜FÕ#ð
ð  ×'Ô'ˆFä! &Ó)ˆDØ×$Ñ$ TÔ*Ø�O‰O˜DÕ!ñ	 (r/   z8Exploding a block reference requires an entity database.é   )	r	   ÚDXFStructureErrorÚdocÚentitydbÚmcountÚmulti_insertÚ
get_layoutÚdelete_entityr   )	r;   r?   r1   r2   r@   rD   Úvirtual_insertÚsource_layoutr>   s	    ```    @r-   r#   r#   :   sð   û€ ðH ÐÜ×%Ñ%Ð&>Ó?Ð?à‡}�}ÐÜ×%Ñ%ØCó
ð 	
÷"ð( �}‰}×%Ñ%€HàÐðBàAóBØð "$€HØ×Ñ˜!ÒØ'×4Ñ4Ö6ˆNÙ% nÕ5ñ 7ñ 	" )Ô,à×(Ñ(Ó*€MØÐ à×#Ñ# IÔ.ô �xÓ Ð ð 	×Ñ˜yÔ)Ü�xÓ Ð r/   >   ÚtagÚflagsÚpromptÚversionÚfield_lengthÚlock_positionÚattribute_typec                óÌ   — | j                  t        ¬«      }t        j                  d|¬«      }| j                  r t        j
                  || j                  «       t        d|«      S )N)ÚdropÚTEXT©Ú
dxfattribsr   )rV   ÚIGNORE_FROM_ATTRIBr
   ÚnewrC   Úbindr   )r<   rV   r=   s      r-   r%   r%   š   sN   € Ø×"Ñ"Ô(:Ð"Ó;€Jô
 �;‰;�v¨*Ô5€DØ‡z‚zÜ�‰�T˜6Ÿ:™:Ô&Ü�˜ÓÐr/   )Úskipped_entity_callbackr1   r2   c             #  óP  ‡‡‡‡‡‡K  — | j                  «       dk(  sJ ‚ddlmŠ ‰xs t        Šd	ˆˆˆfd„}ˆˆˆˆfd„Š| j	                  «       Š| j                  «       }|€-t        j                  d| j                  j                  › d�«      ‚ ‰ ||«      «      E d{  –—†  y7 Œ­w)
aB  Yields 'virtual' parts of block reference `block_ref`.

    This method is meant to examine the block reference entities without the need to
    explode the block reference. The `skipped_entity_callback()` will be called for all
    entities which are not processed, signature:
    :code:`skipped_entity_callback(entity: DXFGraphic, reason: str)`,
    `entity` is the original (untransformed) DXF entity of the block definition,
    the `reason` string is an explanation why the entity was skipped.

    These entities are located at the 'exploded' positions, but are not stored in
    the entity database, have no handle and are not assigned to any layout.

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

    Args:
        block_ref: Block reference entity (INSERT)
        skipped_entity_callback: called whenever the transformation of an entity
            is not supported and so was skipped.
        redraw_order: yield entities in ascending redraw order if ``True``
        copy_strategy: customizable copy strategy

    .. warning::

        **Non uniform scaling** may lead to incorrect results for text entities
        (TEXT, MTEXT, ATTRIB) and maybe some other entities.

    (internal API)

    ÚINSERTr   )ÚEllipsec              3  óJ  •K  — ‰r| j                  «       n| D ]I  }|j                  «       dk(  rŒ	 |j                  ‰¬«      }t        |d«      r|j	                  «        |–— ŒK y # t
        $ r2 t        |d«      r|j                  «       E d {  –—†7   n	 ‰|d«       Y Œ‡w xY w­w)NÚATTDEF)r2   Úremove_associationÚvirtual_entitiesznon copyable)Úentities_in_redraw_orderr6   ÚcopyÚhasattrr`   r   ra   )Úlayoutr+   rc   r2   r1   rZ   s      €€€r-   Údisassemblez5virtual_block_reference_entities.<locals>.disassembleÑ   s¡   øè ø€ Ù;G�f×5Ñ5Ô7ÈVÒSˆFà�~‰~Ó 8Ò+Øð
Ø—{‘{°�{Ó?�ô ˜4Ð!5Ô6Ø×+Ñ+Ô-Ø“
ñ Tøô $ò DÜ˜6Ð#5Ô6Ø%×6Ñ6Ó8×8Ò8á+¨F°NÔCùð	Düs4   ƒ,B#°A%Á#B#Á%(B ÂBÂB ÂB#ÂB Â B#c           	   3  ó  •K  — | D ]  }	 |j                  ‰«       |–— Œ y # t        $ r  ‰|d«       Y Œ0t        $ r¤ |j                  «       }|dv r`t	        |j
                  j                  «      t        kD  r#‰j                  |«      j                  ‰«      –— nD ‰|dt        |«      › d�«       n-|dv r  ‰|j                  «       «      E d {  –—†7   n	 ‰|d«       Y ŒÛt        $ r   ‰t        |‰¬«      «      E d {  –—†7   Y �Œw xY w­w)Nznon transformable>   ÚARCÚCIRCLEzInvalid radius in entity Ú.>   ÚPOLYLINEÚ
LWPOLYLINEzunsupported non-uniform scaling)rZ   )Ú	transformÚNotImplementedErrorr   r6   ÚabsÚdxfÚradiusr   Úfrom_arcr*   ra   r   r!   )r>   r+   r6   r]   ÚmrZ   rm   s      €€€€r-   rm   z3virtual_block_reference_entities.<locals>.transformâ   s  øè ø€ ÛˆFðØ× Ñ  Ô#ð4 “ñ9 øô 'ò EÙ'¨Ð0CÖDÜ)ò WØ Ÿ.™.Ó*�ØÐ/Ñ/Ü˜6Ÿ:™:×,Ñ,Ó-´Ò7Ø%×.Ñ.¨vÓ6×@Ñ@ÀÓCÓCá/Ø"Ð&?ÄÀFÃ¸}ÈAÐ$Nõð Ð :Ñ:Ù(¨×)@Ñ)@Ó)BÓC×CÒCá+¨FÐ4UÔVùÜ,ò ñ %Ü4ØÐ8Oôó÷ ô ð	üsT   ƒDŠ"›D¢D	´D¶BD	ÃCÃD	ÃDÃ!D	Ã?DÄ D	ÄDÄD	Ä	DNzRequired block definition for "z" does not exist.)re   r   ÚreturnúIterable[DXFGraphic])
r6   Úezdxf.entitiesr]   r.   Úmatrix44Úblockr	   rB   rp   Úname)	r;   rZ   r1   r2   rf   Úblock_layoutr]   rs   rm   s	    ```  @@@r-   r!   r!   ¦   sœ   ýè ø€ ðL ×ÑÓ (Ò*Ð*Ð*Ý&à5ÒQÔ9QÐ÷÷"ð> 	×ÑÓ€AØ—?‘?Ó$€LØÐÜ×%Ñ%Ø-¨i¯m©m×.@Ñ.@Ð-AÐARÐSó
ð 	
ñ ™ \Ó2Ó3×3Ò3ús   ˆBB&ÂB$ÂB&ÚPOINTc                óv  — | j                  «       }t        | d«      }|�|t        v rt        j                  d|› d�«      ‚| j
                  €t        j                  |› d�«      ‚| j
                  j                  }|€t        j                  d|› d�«      ‚|€*| j                  «       }|€t        j                  |› d�«      ‚g } |«       D ]$  }|j                  |«       |j                  |«       Œ& | j                  «       }|�|j                  | «       t        |«      S |j                  | «       t        |«      S )aÖ  Explode parts of an entity as primitives into target layout, if target
    layout is ``None``, the target layout is the layout of the source entity.

    Returns an :class:`~ezdxf.query.EntityQuery` container with all DXF parts.

    Args:
        entity: DXF entity to explode, has to have a :meth:`virtual_entities()`
            method
        target_layout: target layout for DXF parts, ``None`` for same layout as
            source entity

    (internal API)

    ra   zCan not explode entity rj   z& has to be assigned to a DXF document.z
Exploding z requires an entity database.z2 without layout assignment, specify target layout.)r6   ÚgetattrÚEXCLUDE_FROM_EXPLODEr	   ÚDXFTypeErrorrC   rB   rD   rG   r7   r9   rH   r   )r+   r?   r6   ra   rD   r>   ÚerJ   s           r-   r$   r$     sZ  € ð" �n‰nÓ€GÜ˜vÐ'9Ó:ÐØÐ 7Ô.BÑ#BÜ× Ñ Ð#:¸7¸)À1Ð!EÓFÐFà‡z�zÐÜ×%Ñ%ØˆiÐ=Ð>ó
ð 	
ð �z‰z×"Ñ"€HØÐÜ×%Ñ%Ø˜˜	Ð!>Ð?ó
ð 	
ð ÐØ×)Ñ)Ó+ˆØÐ Ü×)Ñ)Ø�)ÐMÐNóð ð €HÙÖˆØ× Ñ  Ô#Ø�‰˜Õð  ð ×%Ñ%Ó'€MØÐ Ø×#Ñ# FÔ+ô �xÓ Ð ð 	×Ñ˜vÔ&Ü�xÓ Ð r/   c           	     ó¤  ‡‡‡‡‡— ddl mŠ ˆˆˆˆˆfd„}| j                  «       Št        | j                  j
                  j                  «      Š| j                  «       Šg }| j                  D ]a  Št        ‰t        «      r|j                   |«       g«       Œ+t        ‰t        «      sŒ<|j                  t        ‰t        ‰«      ‰‰«      «       Œc |S )Nr   )Ú
LWPolylinec                 óò   •— ‰j                  t        ‰«      ¬«      } | j                  ‰j                  d¬«       ‰j                  | j
                  _        ‰| j
                  _        ‰j                  | _	        | S )NrU   Úxyb)Úformat)
rX   ÚdictÚappend_formatted_verticesÚverticesÚuzrp   Ú	extrusionÚ	elevationÚ	is_closedÚclosed)Úpr‚   r‹   Úgraphic_attribsÚocsÚpaths    €€€€€r-   Úpolylinez0virtual_boundary_path_entities.<locals>.polylineH  sY   ø€ Ø�N‰N¤d¨?Ó&;ˆNÓ<ˆØ	×#Ñ# D§M¡M¸%Ð#Ô@ØŸ&™&ˆ�‰ŒØ#ˆ�‰ŒØ—>‘>ˆŒØˆr/   )rv   r‚   Úgraphic_propertiesÚfloatrp   r‹   Úzr�   ÚpathsÚ
isinstancer   r9   r   Ú_virtual_edge_pathr†   )Úpolygonr’   r>   r‚   r‹   r�   r�   r‘   s      @@@@@r-   r"   r"   C  s¤   ü€ õ *÷ð ð ×0Ñ0Ó2€OÜ�g—k‘k×+Ñ+×-Ñ-Ó.€IØ
�+‰+‹-€CØ€HØ—”ˆÜ�dœLÔ)Ø�O‰O™X›Z˜LÕ)Ü˜œhÕ'Ø�O‰OÜ" 4¬¨oÓ)>ÀÀYÓOõð	 ð €Or/   c                óÖ  ‡‡— ddl m}m}m}m} ˆˆfd„}ˆfd„}	g }
| j
                  D �]³  }t        |«      }t        |t        «      rL ||j                  «      |d<    ||j                  «      |d<   |
j                  |j                  |¬«      «       Œkt        |t        «      rr|j                  |d<   |j                  |d	<   ‰|d
<   |j                   |d<   |j"                  |d<   ‰j$                  |d<   |
j                  |j                  |¬«      «       Œít        |t&        «      r‰ ||j                  «      |d<    |	|j(                  «      |d<   |j*                  |d<   |j,                  |d<   |j.                  |d<   ‰j$                  |d<   |
j                  |j                  |¬«      «       �Œ†t        |t0        «      s�Œ˜|j                  |¬«      }|j2                  |j4                  _        |j6                  |_        |j:                  D �cg c]
  } ||«      ‘Œ c}|_        |j<                  r|j<                  |_        |j>                  r%|j>                  D �cg c]
  } ||«      ‘Œ c}|_        |j@                  �! |	|j@                  «      |j4                  _         |jB                  �! |	|jB                  «      |j4                  _!        |
j                  |«       �Œ¶ |
S c c}w c c}w )Nr   )ÚLineÚArcr]   ÚSplinec                óX   •— ‰j                  t        | «      j                  ‰¬«      «      S )N)r•   )Úto_wcsr   Úreplace)Úvr‹   r�   s    €€r-   Ú
pnt_to_wcsz&_virtual_edge_path.<locals>.pnt_to_wcsc  s!   ø€ Ø�z‰zœ$˜q›'Ÿ/™/¨I˜/Ó6Ó7Ð7r/   c                ó&   •— ‰j                  | «      S ©N)rŸ   )r¡   r�   s    €r-   Ú
dir_to_wcsz&_virtual_edge_path.<locals>.dir_to_wcsf  s   ø€ Ø�z‰z˜!‹}Ðr/   ÚstartÚendrU   Úcenterrq   r‹   Ústart_angleÚ	end_anglerŠ   Ú
major_axisÚratioÚstart_paramÚ	end_param)"rv   r›   rœ   r]   r�   Úedgesr†   r—   r   r¦   r§   r9   rX   r   r¨   rq   r©   rª   r‰   r   r«   r¬   r­   r®   r   Údegreerp   Úknot_valuesÚknotsÚcontrol_pointsÚweightsÚ
fit_pointsÚstart_tangentÚend_tangent)r‘   rV   r�   r‹   r›   rœ   r]   r�   r¢   r¥   r¯   Úedger:   Úspliner¡   s     ``           r-   r˜   r˜   ^  sk  ù€ ÷ :Ó9õ8ôð !€EØ—
•
ˆÜ�zÓ"ˆÜ�dœHÔ%Ù)¨$¯*©*Ó5ˆG�GÑÙ'¨¯©Ó1ˆG�E‰NØ�L‰L˜Ÿ™¨W˜Ó5Õ6Ü˜œgÔ&Ø $§¡ˆG�HÑØ $§¡ˆG�HÑØ#,ˆG�KÑ ð &*×%5Ñ%5ˆG�MÑ"Ø#'§>¡>ˆG�KÑ Ø#&§6¡6ˆG�KÑ Ø�L‰L˜Ÿ™¨G˜Ó4Õ5Ü˜œkÔ*Ù *¨4¯;©;Ó 7ˆG�HÑÙ$.¨t¯©Ó$?ˆG�LÑ!Ø#Ÿz™zˆG�GÑð &*×%5Ñ%5ˆG�MÑ"Ø#'§>¡>ˆG�KÑ Ø#&§6¡6ˆG�KÑ Ø�L‰L˜Ÿ™°˜Ó8Ö9Ü˜œjÖ)Ø—Z‘Z¨7�ZÓ3ˆFØ $§¡ˆF�J‰JÔØ×+Ñ+ˆFŒLØ<@×<OÒ<OÓ$PÑ<O°q¡Z°¥]Ð<OÑ$PˆFÔ!Ø�|Š|Ø!%§¡�”Ø�ŠØ<@¿OºOÓ$L¹O°q¡Z°¥]¸OÑ$L�Ô!Ø×!Ñ!Ð-Ù+5°d×6HÑ6HÓ+I�—
‘
Ô(Ø×ÑÐ+Ù)3°D×4DÑ4DÓ)E�—
‘
Ô&Ø�L‰L˜Ö ðO ðP €Lùò %Qùò %Ms   ÈK!ÉK&)r;   r   r?   r   rt   r   )r<   r   rt   r   )r;   r   rZ   z+Optional[Callable[[DXFGraphic, str], None]]rt   ru   r¤   )r+   r   r?   zOptional[BaseLayout]rt   r   )r™   r   rt   zlist[list[DXFGraphic]])r‘   r   r�   r   r‹   r”   rt   zlist[DXFGraphic])5Ú
__future__r   ÚloggingÚtypingr   r   r   r   r   Úezdxf.lldxfr	   rv   r
   Úezdxf.entities.boundary_pathsr   r   r   r   r   r   Ú
ezdxf.mathr   r   r   Úezdxf.math.transformtoolsr   r   Úezdxf.queryr   Úezdxf.entities.copyr   r   r   r   r   r   r   Úezdxf.entities.polygonr   Úezdxf.layoutsr   Ú	getLoggerr(   Ú__all__r.   r#   rW   r%   r!   r~   r$   r"   r˜   © r/   r-   Ú<module>rÈ      sF  ðõ #Û ÷õ õ Ý "÷÷ ÷ *Ñ )÷õ $ß >á÷õ õ 2Ý(à	ˆ×	Ñ	˜7Ó	#€ò€òð ØñR!ØðR!àðR!ð óR!òjÐ ó	ð LPØØñb4Øðb4ð Iðb4ð ób4ðJ  �yÐ ð ?Cð2!Øð2!Ø';ð2!àó2!ðjØðàóð64Ø
ð4Ø%(ð4Ø5:ð4àô4r/   