
    Og}                     B   d dl mZ d dlmZmZmZmZ d dlmZ d dl	Z	d dl
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 d dlmZmZ  G d	 d
e	j2                        Z G d dej6                        Z G d de      Z G d de      Z G d d      Z	 d	 	 	 	 	 	 	 	 	 ddZ y)    )annotations)Sequence
NamedTupleAnyIterator)SelfN   )Vec2PathcolorsMatrix44BoundingBox2d)
PropertiesPen)NumpyPath2dNumpyPoints2dc                  l    e Zd ZdZej
                  dd       Zej
                  	 	 	 	 	 	 	 	 dd       Zy)BackendzAAbstract base class for implementing a low level output backends.c                     y)aI  Draws a polyline from a sequence `points`. The input coordinates are page
        coordinates in plot units. The `points` sequence can contain 0 or more
        points!

        Args:
            properties: display :class:`Properties` for the polyline
            points: sequence of :class:`ezdxf.math.Vec2` instances

        N self
propertiespointss      _/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/addons/hpgl2/backend.pydraw_polylinezBackend.draw_polyline    s     	    c                     y)a*  Draws filled or outline paths from the sequence of `paths`. The input coordinates
        are page coordinates in plot units. The `paths` sequence can contain 0 or more
        single :class:`~ezdxf.path.Path` instances. Draws outline paths if
        Properties.FillType is NONE and filled paths otherwise.

        Args:
            properties: display :class:`Properties` for the filled polygon
            paths: sequence of single :class:`ezdxf.path.Path` instances
            filled: draw filled paths if ``True`` otherwise outline paths

        Nr   )r   r   pathsfilleds       r   
draw_pathszBackend.draw_paths-   s     	r   Nr   r   r   zSequence[Vec2]returnNoner   r   r   zSequence[Path]r    boolr#   r$   )__name__
__module____qualname____doc__abcabstractmethodr   r!   r   r   r   r   r      sW    K
 
 	$-;EI	 r   r   c                  r    e Zd Z ej                         Z ej                         Z ej                         Zy)
RecordTypeN)r'   r(   r)   enumautoPOLYLINEFILLED_PATHSOUTLINE_PATHSr   r   r   r.   r.   ?   s)    tyy{H499;LDIIKMr   r.   c                  ,    e Zd ZU ded<   ded<   ded<   y)
DataRecordr.   typeintproperty_hashr   dataN)r'   r(   r)   __annotations__r   r   r   r5   r5   E   s    

Ir   r5   c                  H    e Zd ZdZddZd	dZd
dZ	 	 	 	 	 	 	 	 ddZddZy)RecorderzThe :class:`Recorder` class records the output of the :class:`Plotter` class.

    All input coordinates are page coordinates:

    - 1 plot unit (plu) = 0.025mm
    - 40 plu = 1 mm
    - 1016 plu = 1 inch

    c                .    g | _         i | _        g | _        y N)_records_properties_pensr   s    r   __init__zRecorder.__init__V   s    *,24$&
r   c                B    t        | j                  | j                        S )zReturns a :class:`Player` instance with the original recordings. Make a copy
        of this player to protect the original recordings from being modified::

            safe_player = recorder.player().copy()

        )Playerr?   r@   rB   s    r   playerzRecorder.player[   s     dmmT%5%566r   c                X    | j                  t        j                  |t        |             y r>   )storer.   r1   r   r   s      r   r   zRecorder.draw_polylined   s    

:&&
M&4IJr   c                    t        t        t        |            }|rt        j                  nt        j
                  }| j                  |||       y r>   )tuplemapr   r.   r2   r3   rH   )r   r   r   r    r9   record_types         r   r!   zRecorder.draw_pathsg   s:     Se,-17j--Z=U=U

;
D1r   c                n   |j                         }|| j                  vr|j                         | j                  |<   | j                  j	                  t        |||             t        | j                        t        |j                        k7  r)t        |j                  j                               | _        y y r>   )hashr@   copyr?   appendr5   lenrA   	pen_tablelistvalues)r   rL   r   args	prop_hashs        r   rH   zRecorder.storen   s    OO%	D,,,*4//*;DY'ZYEFtzz?c*"6"677j2299;<DJ 8r   Nr#   r$   )r#   rE   r"   r%   )rL   r.   r   r   r#   r$   )	r'   r(   r)   r*   rC   rF   r   r!   rH   r   r   r   r<   r<   K   sA    '
7K2$2-;2EI2	2=r   r<   c                  T    e Zd ZdZddZddZeZddZddZddZ	ddZ
ddZdd	Zy
)rE   zThis class replays the recordings of the :class:`Recorder` class on another
    backend. The class can modify the recorded output.
    c                >    || _         || _        t               | _        y r>   )r?   r@   r   _bbox)r   recordsr   s      r   rC   zPlayer.__init__|   s    *12<"_
r   c                    t        j                  | j                        }| j                  || j                        }| j
                  j                         |_        |S )zAReturns a new :class:`Player` instance with a copy of recordings.)rO   deepcopyr?   	__class__r@   rZ   )r   r[   rF   s      r   __copy__zPlayer.__copy__   sA    --.)9)9:zz(r   c              #     K   | j                   }| j                  D ]*  }|j                  ||j                     |j                  f , yw)aR  Yields all recordings as `(RecordType, Properties, Data)` tuples.

        The content of the `Data` field is determined by the enum :class:`RecordType`:

        - :attr:`RecordType.POLYLINE` returns a :class:`NumpyPoints2d` instance
        - :attr:`RecordType.FILLED_POLYGON` returns a tuple of :class:`NumpyPath2d` instances

        N)r@   r?   r6   r8   r9   )r   propsrecords      r   
recordingszPlayer.recordings   sH        mm 	HF++uV%9%9:FKKGG	Hs   AA	c                f    | j                   j                  s| j                          | j                   S )zwReturns the bounding box of all recorded polylines and polygons as
        :class:`~ezdxf.math.BoundingBox2d`.
        )rZ   has_dataupdate_bboxrB   s    r   bboxzPlayer.bbox   s'     zz""zzr   c                8   g }| j                   D ]y  }|j                  t        j                  k(  r*|j	                  |j
                  j                                J|j
                  D ]!  }|j	                  |j                                # { t        |      | _        y r>   )	r?   r6   r.   r1   extendr9   extentsr   rZ   )r   r   rb   paths       r   rf   zPlayer.update_bbox   sx    mm 	2F{{j111fkk1134"KK 2DMM$,,.12		2 #6*
r   c                   t               }| j                  }| j                  D ]  }|j                  |j                  |      }|j
                  t        j                  k(  r+|j                  ||j                  j                                g|j                  D cg c]  }|j                          }}|j                  |||j
                  t        j                  k(          yc c}w )z(Replay the recording on another backend.)r    N)r   r@   r?   getr8   r6   r.   r1   r   r9   vertices	to_path2dr!   r2   )r   backendcurrent_propsra   rb   pr   s          r   replayzPlayer.replay   s    "  mm 	F!IIf&:&:MJM{{j111%%mV[[5I5I5KL06<1<<""!5
@W@W1W # 	
 =s   C#c                x   | j                   D ]]  }|j                  t        j                  k(  r|j                  j                  |       <|j                  D ]  }|j                  |        _ | j                  j                  r8t        |j                  | j                  j                                     | _        yy)zpTransforms the recordings by a transformation matrix `m` of type
        :class:`~ezdxf.math.Matrix44`.
        N)r?   r6   r.   r1   r9   transform_inplacerZ   re   r   fast_2d_transformrect_vertices)r   mrb   rk   s       r   	transformzPlayer.transform   s     mm 	.F{{j111--a0"KK .D**1-.		. ::&q':':4::;S;S;U'VWDJ r   c                   g }g }t               }| j                  }| j                  D ]  }|j                  t        j
                  k(  rS|j                  |j                  |      }t        j                  |j                               }|j                  ||f       s|j                  |        |j                  d d       |D cg c]  }|d   	 }}|j                  |       || _        yc c}w )zSort filled paths by descending luminance (from light to dark).

        This also changes the plot order in the way that all filled paths are plotted
        before polylines and outline paths.
        c                    | d   S )Nr   r   )rs    r   <lambda>z*Player.sort_filled_paths.<locals>.<lambda>   s
    AaD r   T)keyreverser	   N)r   r@   r?   r6   r.   r2   rm   r8   r   	luminanceresolve_fill_colorrP   sortri   )	r   fillingsoutlinescurrentra   rb   r~   sort_recr[   s	            r   sort_filled_pathszPlayer.sort_filled_paths   s     ,  mm 	(F{{j555))F$8$8'B&&w'A'A'CDf.'	( 	.$7/7888A;88x  9s   C,N)r[   zlist[DataRecord]r   zdict[int, Properties])r#   r   )r#   z,Iterator[tuple[RecordType, Properties, Any]])r#   r   rW   )rp   r   r#   r$   )rx   r   r#   r$   )r'   r(   r)   r*   rC   r_   rO   rc   rg   rf   rs   ry   r   r   r   r   rE   rE   w   s8    %
 DH+X r   rE   c                p   t        |      dk  rd}t        |      dk  rd}t        j                  ||d      }|r+|t        j                  t	        j
                  |            z  }|j                  | j                               }t        |      j                  \  }}|t        j                  | | d      z  S )zdReturns a matrix to place the bbox in the first quadrant of the coordinate
    system (+x, +y).
    g&.>      ?r   )absr   scalez_rotatemathradiansrv   rw   r   extmin	translate)rg   sxsyrotationrx   cornerstxtys           r   placement_matrixr      s     2w~
2w~r2s#A	Xt||H566!!$"4"4"67G7#**FBx!!2#sA...r   )r   r   g        )
rg   r   r   floatr   r   r   r   r#   r   )!
__future__r   typingr   r   r   r   typing_extensionsr   r+   rO   r/   r   depsr
   r   r   r   r   r   r   r   ezdxf.npshapesr   r   ABCr   Enumr.   r5   r<   rE   r   r   r   r   <module>r      s    # 6 6 " 
     ( 5cgg D    )=w )=Xd  d P NQ/
/"/.3/EJ//r   