
    'j}                     <   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	j                  Z G d dej                  Z G d de          Z G d de          Z G d d          Z	 dddZ dS )     )annotations)Sequence
NamedTupleAnyIterator)SelfN   )Vec2PathcolorsMatrix44BoundingBox2d)
PropertiesPen)NumpyPath2dNumpyPoints2dc                  V    e Zd ZdZej        dd            Zej        dd            ZdS )BackendzAAbstract base class for implementing a low level output backends.
propertiesr   pointsSequence[Vec2]returnNonec                    dS )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 selfr   r   s      T/DATA/AppData/hermes/venv/lib/python3.11/site-packages/ezdxf/addons/hpgl2/backend.pydraw_polylinezBackend.draw_polyline    s	     	    pathsSequence[Path]filledboolc                    dS )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   r!   r#   s       r   
draw_pathszBackend.draw_paths-   s	     	r    Nr   r   r   r   r   r   r   r   r!   r"   r#   r$   r   r   )__name__
__module____qualname____doc__abcabstractmethodr   r&   r   r    r   r   r      s`        KK
 
 
 
 	     r    r   c                  h    e Zd Z ej                    Z ej                    Z ej                    ZdS )
RecordTypeN)r)   r*   r+   enumautoPOLYLINEFILLED_PATHSOUTLINE_PATHSr   r    r   r0   r0   ?   s5        ty{{H49;;LDIKKMMMr    r0   c                  .    e Zd ZU ded<   ded<   ded<   dS )
DataRecordr0   typeintproperty_hashr   dataN)r)   r*   r+   __annotations__r   r    r   r7   r7   E   s1         IIIIIr    r7   c                  :    e Zd ZdZddZddZddZddZddZdS )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

    r   r   c                0    g | _         i | _        g | _        d S N)_records_properties_pensr   s    r   __init__zRecorder.__init__V   s    *,24$&


r    Playerc                6    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()

        )rF   rA   rB   rD   s    r   playerzRecorder.player[   s     dmT%5666r    r   r   r   r   c                b    |                      t          j        |t          |                     d S r@   )storer0   r3   r   r   s      r   r   zRecorder.draw_polylined   s)    

:&
M&4I4IJJJJJr    r!   r"   r#   r$   c                    t          t          t          |                    }|rt          j        nt          j        }|                     |||           d S r@   )tuplemapr   r0   r4   r5   rJ   )r   r   r!   r#   r;   record_types         r   r&   zRecorder.draw_pathsg   sL     Se,,--17Uj--Z=U

;
D11111r    rN   r0   c                x   |                                 }|| j        vr|                                | j        |<   | j                            t          |||                     t          | j                  t          |j                  k    r-t          |j        
                                          | _        d S d S r@   )hashrB   copyrA   appendr7   lenrC   	pen_tablelistvalues)r   rN   r   args	prop_hashs        r   rJ   zRecorder.storen   s    OO%%	D,,,*4//*;*;DY'ZYEEFFFtz??c*"67777j299;;<<DJJJ 87r    Nr   r   )r   rF   r'   r(   )rN   r0   r   r   r   r   )	r)   r*   r+   r,   rE   rH   r   r&   rJ   r   r    r   r>   r>   K   s         ' ' ' '
7 7 7 7K K K K2 2 2 2= = = = = =r    r>   c                  V    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dS )rF   zThis class replays the recordings of the :class:`Recorder` class on another
    backend. The class can modify the recorded output.
    recordslist[DataRecord]r   dict[int, Properties]c                H    || _         || _        t                      | _        d S r@   )rA   rB   r   _bbox)r   r[   r   s      r   rE   zPlayer.__init__|   s     *12<"__


r    r   r   c                    t          j        | j                  }|                     || j                  }| j                                         |_        |S )zAReturns a new :class:`Player` instance with a copy of recordings.)rQ   deepcopyrA   	__class__rB   r_   )r   r[   rH   s      r   __copy__zPlayer.__copy__   sA    -..)9::z((r    ,Iterator[tuple[RecordType, Properties, Any]]c              #  d   K   | j         }| j        D ]}|j        ||j                 |j        fV  dS )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)rB   rA   r8   r:   r;   )r   propsrecords      r   
recordingszPlayer.recordings   sQ        m 	H 	HF+uV%9:FKGGGGG	H 	Hr    r   c                P    | j         j        s|                                  | j         S )zwReturns the bounding box of all recorded polylines and polygons as
        :class:`~ezdxf.math.BoundingBox2d`.
        )r_   has_dataupdate_bboxrD   s    r   bboxzPlayer.bbox   s+     z" 	zr    r   c                ,   g }| j         D ]u}|j        t          j        k    r-|                    |j                                                   D|j        D ])}|                    |                                           *vt          |          | _        d S r@   )	rA   r8   r0   r3   extendr;   extentsr   r_   )r   r   rg   paths       r   rk   zPlayer.update_bbox   s    m 	2 	2F{j111fk11334444"K 2 2DMM$,,..11112"6**


r    backendr   c                x   t                      }| j        }| j        D ]}|                    |j        |          }|j        t          j        k    r.|                    ||j	        
                                           `d |j	        D             }|                    |||j        t          j        k               dS )z(Replay the recording on another backend.c                6    g | ]}|                                 S r   )	to_path2d).0ps     r   
<listcomp>z!Player.replay.<locals>.<listcomp>   s     <<<1<<<r    )r#   N)r   rB   rA   getr:   r8   r0   r3   r   r;   verticesr&   r4   )r   rq   current_propsrf   rg   r!   s         r   replayzPlayer.replay   s    " m 	 	F!IIf&:MJJM{j111%%mV[5I5I5K5KLLLL<<<<<""!5
@W1W #    	 	r    mr   c                P   | j         D ]Q}|j        t          j        k    r|j                            |           2|j        D ]}|                    |           R| j        j        r@t          |	                    | j        
                                                    | _        dS dS )zpTransforms the recordings by a transformation matrix `m` of type
        :class:`~ezdxf.math.Matrix44`.
        N)rA   r8   r0   r3   r;   transform_inplacer_   rj   r   fast_2d_transformrect_vertices)r   r|   rg   rp   s       r   	transformzPlayer.transform   s     m 	. 	.F{j111--a0000"K . .D**1----. : 	X&q':':4:;S;S;U;U'V'VWWDJJJ	X 	Xr    c                   g }g }t                      }| j        }| j        D ]}|j        t          j        k    rY|                    |j        |          }t          j	        |
                                          }|                    ||f           p|                    |           |                    d d           d |D             }|                    |           || _        dS )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reversec                    g | ]
}|d          S )r	   r   )ru   sort_recs     r   rw   z,Player.sort_filled_paths.<locals>.<listcomp>   s    88888A;888r    N)r   rB   rA   r8   r0   r4   rx   r:   r   	luminanceresolve_fill_colorrR   sortrn   )r   fillingsoutlinescurrentrf   rg   r   r[   s           r   sort_filled_pathszPlayer.sort_filled_paths   s     ,, m 	( 	(F{j555))F$8'BB&w'A'A'C'CDDf....''''..$77788x888x   r    N)r[   r\   r   r]   )r   r   )r   rd   )r   r   rY   )rq   r   r   r   )r|   r   r   r   )r)   r*   r+   r,   rE   rc   rQ   rh   rl   rk   r{   r   r   r   r    r   rF   rF   w   s         % % % %
    DH H H H   + + + +   X X X X           r    rF         ?        rl   r   sxfloatsyrotationr   r   c                   t          |          dk     rd}t          |          dk     rd}t          j        ||d          }|r)|t          j        t	          j        |                    z  }|                    |                                           }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   r   )absr   scalez_rotatemathradiansr   r   r   extmin	translate)rl   r   r   r   r|   cornerstxtys           r   placement_matrixr      s     2ww~~
2ww~~r2s##A 7	Xt|H55666!!$"4"4"6"677G7##*FBx!2#sA....r    )r   r   r   )
rl   r   r   r   r   r   r   r   r   r   )!
__future__r   typingr   r   r   r   typing_extensionsr   r-   rQ   r1   r   depsr
   r   r   r   r   r   r   r   ezdxf.npshapesr   r   ABCr   Enumr0   r7   r>   rF   r   r   r    r   <module>r      s   # " " " " " 6 6 6 6 6 6 6 6 6 6 6 6 " " " " " " 



                 ( ' ' ' ' ' ' ' 5 5 5 5 5 5 5 5    cg   D                      )= )= )= )= )=w )= )= )=Xd  d  d  d  d  d  d  d P NQ/ / / / / / /r    