
    h%7                       S SK Jr  S SKrS SKJrJrJrJrJr  S SK	J
r
  S SKJr  S SKJrJrJrJrJrJr  S SKJrJrJr  S SKJrJr  S S	KJr  S S
KJrJr  \(       a  S SKJ r J!r!J"r"J#r#J$r$  S SK%J&r&  S SK'J(r(  \RR                  " S5      r*/ SQr+S r,S\S.     SS jjr-1 Skr.SS jr/SS\S.     SS jjr0S1r1 S     S S jjr2    S!S jr3        S"S jr4g)#    )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    [         R                  S[        U 5       SU S35        g )Nz,(Virtual Block Reference Entities) Ignoring z: "")loggerdebugstr)entityreasons     ?/var/www/html/env/lib/python3.13/site-packages/ezdxf/explode.pydefault_logging_callbackr.   4   s$    
LL
6s6{m3vhaP    Fredraw_ordercopy_strategyc                 ^^^^ Tc  [         R                  " S5      eU R                  c  [         R                  " S5      eUUUU4S jnU R                  R                  nUc   S5       e/ mU R                  S:  a   U R                  5        H  nU" U5        M     OU" U 5        U R                  5       nUb  UR                  U 5        OUR                  U 5        [        T5      $ )a  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                N  > [        U TTS9 HU  nUR                  5       nTR                  U5        US:X  a  [        SU5      R	                  5         TR                  U5        MW     U R                   H0  n[        U5      nTR                  U5        TR                  U5        M2     g )Nr0   	DIMENSIONr   )r!   dxftype
add_entityr   renderappendattribsr%   )		block_refr+   r6   attribtextr2   entitiesr1   target_layouts	        r-   _explode_single_block_ref:explode_block_reference.<locals>._explode_single_block_reff   s    6L
F nn&G$$V,+% [&)002OOF#
  ''F!&)D$$T*OOD!	 (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@   rE   virtual_insertsource_layoutr>   s	    ```    @r-   r#   r#   :   s    H %%&>??}}%%C
 	
" "( }}%%HBAB "$H!'446N%n5 7 	"),((*M ##I.y)x  r/   >   tagflagspromptversionfield_lengthlock_positionattribute_typec                    U R                  [        S9n[        R                  " SUS9nU R                  (       a   [        R
                  " X R                  5        [        SU5      $ )N)dropTEXT
dxfattribsr   )rW   IGNORE_FROM_ATTRIBr
   newrD   bindr   )r<   rW   r=   s      r-   r%   r%      sL    ""(:";J
 ;;v*5DzzT::&r/   )skipped_entity_callbackr1   r2   c             #  f  ^^^^^^#    U R                  5       S:X  d   eSSKJm  T=(       d    [        mS	UUU4S jjnUUUU4S jmU R	                  5       mU R                  5       nUc.  [        R                  " SU R                  R                   S35      eT" U" U5      5       Sh  vN   g N7f)
a  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  r  >#    T(       a  U R                  5       OU  HN  nUR                  5       S:X  a  M   UR                  TS9n[        US5      (       a  UR	                  5         Uv   MP     g ! [
         a:    [        US5      (       a  UR                  5        S h  vN     M  T" US5         M  f = f7f)NATTDEF)r2   remove_associationvirtual_entitiesznon copyable)entities_in_redraw_orderr6   copyhasattrra   r   rb   )layoutr+   rd   r2   r1   r[   s      r-   disassemble5virtual_block_reference_entities.<locals>.disassemble   s     ;Gf557VSF~~8+
{{{? 4!566++-
 T $ D6#566%66888+FNC	Ds@   3B7A0*B70.B4B!B4$B7'	B40B73B44B7c           	   3  <  >#    U  H  n UR                  T5        Uv   M     g ! [         a    T" US5         M4  [         a    UR                  5       nUS;   ae  [	        UR
                  R                  5      [        :  a%  TR                  U5      R                  T5      v    M  T" US[        U5       S35         M  US;   a"  T" UR                  5       5       S h  vN     M  T" US5         M  [         a    T" [        UTS95       S h  vN     GM  f = f7f)Nznon transformable>   ARCCIRCLEzInvalid radius in entity .>   POLYLINE
LWPOLYLINEzunsupported non-uniform scaling)r[   )	transformNotImplementedErrorr   r6   absdxfradiusr   from_arcr*   rb   r   r!   )r>   r+   r6   r^   mr[   ro   s      r-   ro   3virtual_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+F4UV,  %48O  	sx   D$	DDDA(D"D%D;D>DC D#D&	D/D2DDDDDDNzRequired block definition for "z" does not exist.)rf   r   returnIterable[DXFGraphic])
r6   ezdxf.entitiesr^   r.   matrix44blockr	   rC   rr   name)	r;   r[   r1   r2   rg   block_layoutr^   ru   ro   s	    ```  @@@r-   r!   r!      s     L (***&5Q9Q " > 	A??$L%%-imm.@.@-AARS
 	
 \2333s   B!B1)B/*B1POINTc                ~   U R                  5       n[        U S5      nUb
  U[        ;   a  [        R                  " SU S35      eU R
                  c  [        R                  " U S35      eU R
                  R                  nUc  [        R                  " SU S35      eUc,  U R                  5       nUc  [        R                  " U S35      e/ nU" 5        H%  nUR                  U5        UR                  U5        M'     U R                  5       nUb  UR                  U 5        OUR                  U 5        [        U5      $ )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)

rb   zCan not explode entity rl   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	   DXFTypeErrorrD   rC   rE   rH   r7   r9   rI   r   )r+   r?   r6   rb   rE   r>   erK   s           r-   r$   r$     sK   " nnGv'9:7.B#B  #:7)1!EFFzz%%i=>
 	
 zz""H%%	!>?
 	
 ))+ )))MN  H  #   %%'M ##F+v&x  r/   c           	       ^^^^^ SSK Jm  UUUUU4S jnU R                  5       m[        U R                  R
                  R                  5      mU R                  5       m/ nU R                   Hn  m[        T[        5      (       a  UR                  U" 5       /5        M1  [        T[        5      (       d  MH  UR                  [        T[        T5      TT5      5        Mp     U$ )Nr   )
LWPolylinec                    > TR                  [        T5      S9n U R                  TR                  SS9  TR                  U R
                  l        TU R
                  l        TR                  U l	        U $ )NrV   xyb)format)
rY   dictappend_formatted_verticesverticesuzrr   	extrusion	elevation	is_closedclosed)pr   r   graphic_attribsocspaths    r-   polyline0virtual_boundary_path_entities.<locals>.polylineH  sY    NNd?&;N<	##DMM%#@&&#>>r/   )ry   r   graphic_propertiesfloatrr   r   zr   paths
isinstancer   r9   r   _virtual_edge_pathr   )polygonr   r>   r   r   r   r   r   s      @@@@@r-   r"   r"   C  s     *  002Ogkk++--.I
++-CHdL))OOXZL)h''OO"4o)>YO	  Or/   c                  ^^ SSK JnJnJnJn  UU4S jnU4S jn	/ n
U R
                   GH  n[        U5      n[        U[        5      (       aJ  U" UR                  5      US'   U" UR                  5      US'   U
R                  UR                  US95        Mn  [        U[        5      (       ap  UR                  US'   UR                  US	'   TUS
'   UR                   US'   UR"                  US'   TR$                  US'   U
R                  UR                  US95        M  [        U[&        5      (       a  U" UR                  5      US'   U	" UR(                  5      US'   UR*                  US'   UR,                  US'   UR.                  US'   TR$                  US'   U
R                  UR                  US95        GM  [        U[0        5      (       d  GM  UR                  US9nUR2                  UR4                  l        UR6                  Ul        UR:                   Vs/ s H
  o" U5      PM     snUl        UR<                  (       a  UR<                  Ul        UR>                  (       a'  UR>                   Vs/ s H
  o" U5      PM     snUl        UR@                  b!  U	" UR@                  5      UR4                  l         URB                  b!  U	" URB                  5      UR4                  l!        U
R                  U5        GM     U
$ s  snf s  snf )Nr   )LineArcr^   Splinec                R   > TR                  [        U 5      R                  TS95      $ )N)r   )to_wcsr   replace)vr   r   s    r-   
pnt_to_wcs&_virtual_edge_path.<locals>.pnt_to_wcsc  s!    zz$q'//I/677r/   c                &   > TR                  U 5      $ N)r   )r   r   s    r-   
dir_to_wcs&_virtual_edge_path.<locals>.dir_to_wcsf  s    zz!}r/   startendrV   centerrs   r   start_angle	end_angler   
major_axisratiostart_param	end_param)"ry   r   r   r^   r   edgesr   r   r   r   r   r9   rY   r   r   rs   r   r   r   r   r   r   r   r   r   degreerr   knot_valuesknotscontrol_pointsweights
fit_pointsstart_tangentend_tangent)r   rW   r   r   r   r   r^   r   r   r   r   edger:   spliner   s     ``           r-   r   r   ^  sw    :98 !E

z"dH%%)$**5GG'1GENLLW56g&& $GH $GH#,GK  &*%5%5GM"#'>>GK #&66GK LLG45k** *4;; 7GH$.t$?GL!#zzGG &*%5%5GM"#'>>GK #&66GK LL89j))ZZ7Z3F $FJJ++FL<@<O<O$P<OqZ]<O$PF!||!%<@OO$LOqZ]O$L!!!-+5d6H6H+I

(+)3D4D4D)E

&LL O P L %Q %Ms   L4L)r;   r   r?   r   rw   r   )r<   r   rw   r   )r;   r   r[   z+Optional[Callable[[DXFGraphic, str], None]]rw   rx   r   )r+   r   r?   zOptional[BaseLayout]rw   r   )r   r   rw   zlist[list[DXFGraphic]])r   r   r   r   r   r   rw   zlist[DXFGraphic])5
__future__r   loggingtypingr   r   r   r   r   ezdxf.lldxfr	   ry   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#   rX   r%   r!   r   r$   r"   r    r/   r-   <module>r      sD   #    "  * ) $ >  2(			7	# R!R!R! R!j 	 LPb4b4 Ib4 b4J  y  ?C2!2!';2!2!j64
4%(45:44r/   