
    Dgs>                       U 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 d dlZd dl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 d dlmZ d	d
lmZmZ d	dlmZ d	dl m!Z! d	dl"m#Z#  G d dejH                        Z% G d de%      Z& G d de%      Z' G d de%      Z( G d de%      Z) G d de%      Z* G d de      Z+ G d de      Z,ee!ge,f   Z-de.d<    G d  d!      Z/	 	 	 	 	 	 	 	 d#d"Z0y)$    )annotations)IterableIteratorSequenceCallableOptional
NamedTuple)Self	TypeAliasN)BoundingBox2dMatrix44Vec2UVec)NumpyPath2dNumpyPoints2dEmptyShapeError)take2)ClippingRect   )BackendInterface	ImageData)Configuration)BackendProperties)Colorc                  `    e Zd ZddZej
                  dd       Zej
                  dd       Zy)
DataRecordc                     d| _         d| _        y )Nr    )property_hashhandleselfs    \/var/www/html/public_html/venv/lib/python3.12/site-packages/ezdxf/addons/drawing/recorder.py__init__zDataRecord.__init__   s    "#    c                     y N r!   s    r#   bboxzDataRecord.bbox        r%   c                     y r'   r(   r"   ms     r#   transform_inplacezDataRecord.transform_inplace$   r*   r%   NreturnNoner0   r   r-   r   r0   r1   )__name__
__module____qualname__r$   abcabstractmethodr)   r.   r(   r%   r#   r   r      s;     	  	 r%   r   c                  0     e Zd Zd fdZddZddZ xZS )PointsRecordc                0    t         |           || _        y r'   )superr$   points)r"   r=   	__class__s     r#   r$   zPointsRecord.__init__+   s    %+r%   c                h    	 | j                   j                         S # t        $ r Y t               S w xY wr'   )r=   r)   r   r   r!   s    r#   r)   zPointsRecord.bbox/   s4    	;;##%% 		    	11c                :    | j                   j                  |       y r'   )r=   r.   r,   s     r#   r.   zPointsRecord.transform_inplace6   s    %%a(r%   )r=   r   r0   r1   r2   r3   r4   r5   r6   r$   r)   r.   __classcell__r>   s   @r#   r:   r:   )   s    ,)r%   r:   c                  0     e Zd Zd fdZddZddZ xZS )SolidLinesRecordc                0    t         |           || _        y r'   )r<   r$   lines)r"   rH   r>   s     r#   r$   zSolidLinesRecord.__init__;   s    $)
r%   c                h    	 | j                   j                         S # t        $ r Y t               S w xY wr'   )rH   r)   r   r   r!   s    r#   r)   zSolidLinesRecord.bbox?   s2    	::??$$ 		r@   c                :    | j                   j                  |       y r'   )rH   r.   r,   s     r#   r.   z"SolidLinesRecord.transform_inplaceF   s    

$$Q'r%   )rH   r   r0   r1   r2   r3   rB   rD   s   @r#   rF   rF   :   s    *(r%   rF   c                  0     e Zd Zd fdZddZddZ xZS )
PathRecordc                0    t         |           || _        y r'   )r<   r$   path)r"   rN   r>   s     r#   r$   zPathRecord.__init__K   s    !%	r%   c                h    	 | j                   j                         S # t        $ r Y t               S w xY wr'   )rN   r)   r   r   r!   s    r#   r)   zPathRecord.bboxO   s2    	99>>## 		r@   c                :    | j                   j                  |       y r'   )rN   r.   r,   s     r#   r.   zPathRecord.transform_inplaceV   s    		##A&r%   )rN   r   r0   r1   r2   r3   rB   rD   s   @r#   rL   rL   J   s    &'r%   rL   c                  0     e Zd Zd fdZddZddZ xZS )FilledPathsRecordc                0    t         |           || _        y r'   )r<   r$   paths)r"   rT   r>   s     r#   r$   zFilledPathsRecord.__init__[   s    ,1
r%   c                    t               }| j                  D ]-  }t        |      s|j                  |j	                                / |S r'   )r   rT   lenextendextents)r"   r)   rN   s      r#   r)   zFilledPathsRecord.bbox_   s<    JJ 	,D4yDLLN+	, r%   c                H    | j                   D ]  }|j                  |        y r'   )rT   r.   )r"   r-   rN   s      r#   r.   z#FilledPathsRecord.transform_inplacef   s#    JJ 	&D""1%	&r%   )rT   Sequence[NumpyPath2d]r0   r1   r2   r3   rB   rD   s   @r#   rR   rR   Z   s    2&r%   rR   c                  0     e Zd Zd fdZddZddZ xZS )ImageRecordc                >    t         |           || _        || _        y r'   )r<   r$   boundary
image_data)r"   r^   r_   r>   s      r#   r$   zImageRecord.__init__l   s    '/%/r%   c                h    	 | j                   j                         S # t        $ r Y t               S w xY wr'   )r^   r)   r   r   r!   s    r#   r)   zImageRecord.bboxq   s4    	==%%'' 		r@   c                x    | j                   j                  |       | j                  xj                  |z  c_        y r'   )r^   r.   r_   	transformr,   s     r#   r.   zImageRecord.transform_inplacex   s)    ''*!!Q&!r%   )r^   r   r_   r   r0   r1   r2   r3   rB   rD   s   @r#   r\   r\   k   s    0
'r%   r\   c                      e Zd ZdZddZddZddZddZddZddZ	ddZ
	 	 	 	 	 	 dd	Zdd
Z	 	 	 	 	 	 ddZ	 	 	 	 	 	 ddZddZddZddZddZddZy)Recorderz)Records the output of the Frontend class.c                \    t               | _        d| _        g | _        t	               | _        y )N#000000)r   config
backgroundrecordsdict
propertiesr!   s    r#   r$   zRecorder.__init__   s"    #o!*)+8<r%   c                    t               }| j                  |_        | j                  |_        | j                  |_        | j                  |_        d|_        |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()

        T)Playerrg   rh   ri   rk   has_shared_recordingsr"   players     r#   rp   zRecorder.player   sF      OO OO'+$r%   c                    || _         y r'   )rg   )r"   rg   s     r#   	configurezRecorder.configure   s	    r%   c                    || _         y r'   )rh   )r"   colors     r#   set_backgroundzRecorder.set_background   s	    r%   c                    t        |d d       }||_        |j                  |_        | j                  j	                  |       || j
                  |<   y )N   )hashr   r    ri   appendrk   )r"   recordrk   	prop_hashs       r#   storezRecorder.store   sI     BQ(	("))F#%/	"r%   c                N    | j                  t        t        |f            |       y r'   r|   r:   r   )r"   posrk   s      r#   
draw_pointzRecorder.draw_point   s    

<sf 56
Cr%   c                P    | j                  t        t        ||f            |       y r'   r~   )r"   startendrk   s       r#   	draw_linezRecorder.draw_line   s    

<ucl ;<jIr%   c                d    dfd}| j                  t        t         |                   |       y )Nc               3  2   K   D ]  \  } }|  |  y wr'   r(   )serH   s     r#   flattenz*Recorder.draw_solid_lines.<locals>.flatten   s$      1s   )r0   zIterator[Vec2])r|   rF   r   )r"   rH   rk   r   s    `  r#   draw_solid_lineszRecorder.draw_solid_lines   s%    	
 	

#M')$<=zJr%   c                ^    t        |t              sJ | j                  t        |      |       y r'   )
isinstancer   r|   rL   )r"   rN   rk   s      r#   	draw_pathzRecorder.draw_path   s%    $,,,

:d#Z0r%   c                ^    t        |t              sJ | j                  t        |      |       y r'   )r   r   r|   r:   )r"   r=   rk   s      r#   draw_filled_polygonzRecorder.draw_filled_polygon   s'     &-000

<'4r%   c                    t        |      }t        |      dk(  ry t        |d   t              sJ | j	                  t        |      |       y )Nr   )tuplerV   r   r   r|   rR   )r"   rT   rk   s      r#   draw_filled_pathszRecorder.draw_filled_paths   sC     eu:?%(K000

$U+Z8r%   c                    t        j                  |j                        }|j                  |j                         | j                  t        ||      |       y r'   )copydeepcopypixel_boundary_pathr.   rb   r|   r\   )r"   r_   rk   r^   s       r#   
draw_imagezRecorder.draw_image   s?    ==!?!?@"":#7#78

;x4jAr%   c                     y r'   r(   )r"   entityrk   s      r#   enter_entityzRecorder.enter_entity       r%   c                     y r'   r(   )r"   r   s     r#   exit_entityzRecorder.exit_entity   r   r%   c                    t               r'   )NotImplementedErrorr!   s    r#   clearzRecorder.clear   s    !##r%   c                     y r'   r(   r!   s    r#   finalizezRecorder.finalize   r   r%   Nr/   )r0   rm   )rg   r   r0   r1   )rt   r   r0   r1   )rz   r   rk   r   r0   r1   )r   r   rk   r   r0   r1   )r   r   r   r   rk   r   r0   r1   )rH   zIterable[tuple[Vec2, Vec2]]rk   r   r0   r1   )rN   r   rk   r   r0   r1   )r=   r   rk   r   r0   r1   )rT   zIterable[NumpyPath2d]rk   r   r0   r1   )r_   r   rk   r   r0   r1   )r4   r5   r6   __doc__r$   rp   rr   ru   r|   r   r   r   r   r   r   r   r   r   r   r   r(   r%   r#   rd   rd   }   s    3? 0DJK0K>OK	K15#51B5	59*98I9	9B$r%   rd   c                  *    e Zd ZU dZded<   dZded<   y)OverridezRepresents the override state for a data record.

    Attributes:
        properties: original or modified :class:`BackendProperties`
        is_visible: override visibility e.g. switch layers on/off

    r   rk   Tbool
is_visibleN)r4   r5   r6   r   __annotations__r   r(   r%   r#   r   r      s     "!Jr%   r   r   OverrideFuncc                  b    e Zd ZdZddZddZeZddZ	 d	 	 	 	 	 ddZddZ	ddZ
dd	Zdd
Zy)rm   zIPlays the recordings of the :class:`Recorder` backend on another backend.c                    t               | _        d| _        g | _        t	               | _        t               | _        d| _        y )Nrf   F)	r   rg   rh   ri   rj   rk   r   _bboxrn   r!   s    r#   r$   zPlayer.__init__   s3    #o!*)+8<"_
+0"r%   c                    | j                         }| j                  |_        | j                  |_        t        j                  | j
                        |_        | j                  |_        d|_        |S )z8Returns a copy of the player with non-shared recordings.F)r>   rg   rh   r   r   ri   rk   rn   ro   s     r#   __copy__zPlayer.__copy__   sR    ! OOt||4 OO',$r%   c              #     K   | j                   }| j                  D ]/  }t        g ||j                     dd |j                   }||f 1 yw)zBYields all recordings as `(DataRecord, BackendProperties)` tuples.Nrw   )rk   ri   r   r   r    )r"   propsrz   rk   s       r#   
recordingszPlayer.recordings  s_     ll 	%F* v++,Ra028--J *$$		%s   AANc                   |j                  | j                         |j                  | j                         | j	                         D ]  \  }}|r! ||      }|j
                  s|j                  }t        |t              rt        |j                        }|dk(  rU|dkD  r|j                  |j                  |       w|j                  j                         }t        |      dk(  r|j                  |d   |       |j                  |d   |d   |       t        |t              r5|j!                  t#        |j$                  j                               |       t        |t&              r|j)                  |j*                  |       Bt        |t,              r|j/                  |j0                  |       pt        |t2              s|j5                  |j6                  |        |j9                          y)a9  Replay the recording on another backend that implements the
        :class:`BackendInterface`. The optional `override` function can be used to
        override the properties and state of data records, it gets the :class:`BackendProperties`
        as input and must return an :class:`Override` instance.
        r      r   N)rr   rg   ru   rh   r   r   rk   r   r:   rV   r=   r   verticesr   r   rF   r   r   rH   rL   r   rN   rR   r   rT   r\   r   r_   r   )r"   backendoverriderz   rk   statecountr   s           r#   replayzPlayer.replay  s    	$++&t/"&//"3 	BFJ ,''"--
&,/FMM*A:19//zJ!==113x=A%&&x{J?%%hqk8A;
KF$45((v||/D/D/F)GTFJ/!!&++z:F$56))&,,
CFK0""6#4#4jA3	B4 	r%   c                    | j                   D ]  }|j                  |        | j                  j                  r8t	        |j                  | j                  j                                     | _        yy)zxTransforms the recordings inplace by a transformation matrix `m` of type
        :class:`~ezdxf.math.Matrix44`.
        N)ri   r.   r   has_datar   fast_2d_transformrect_vertices)r"   r-   rz   s      r#   rb   zPlayer.transform5  s]     ll 	(F$$Q'	( ::&q':':4::;S;S;U'VWDJ r%   c                f    | j                   j                  s| j                          | j                   S )zNReturns the bounding box of all records as :class:`~ezdxf.math.BoundingBox2d`.)r   r   update_bboxr!   s    r#   r)   zPlayer.bbox@  s%    zz""zzr%   c                    t               }| j                  D ]!  }|j                  |j                                # || _        y r'   )r   ri   rW   r)   r   )r"   r)   rz   s      r#   r   zPlayer.update_bboxF  s5    ll 	'FKK&	'
r%   c                    t        t        |      t        |      g      }t        | j                  ||      | _        t               | _        y)a  Crop recorded shapes inplace by a rectangle defined by two points.

        The argument `distance` defines the approximation precision for paths which have
        to be approximated as polylines for cropping but only paths which are really get
        cropped are approximated, paths that are fully inside the crop box will not be
        approximated.

        Args:
            p1: first corner of the clipping rectangle
            p2: second corner of the clipping rectangle
            distance: maximum distance from the center of the curve to the
                center of the line segment between two approximation points to
                determine if a segment should be subdivided.

        N)r   r   crop_records_rectri   r   )r"   p1p2distance	crop_rects        r#   r   zPlayer.crop_rectL  s8      "48T"X"67	(y(K"_
r%   r/   )r0   r
   )r0   z.Iterator[tuple[DataRecord, BackendProperties]]r'   )r   r   r   zOptional[OverrideFunc]r0   r1   r3   r2   )r   r   r   r   r   floatr0   r1   )r4   r5   r6   r   r$   r   r   r   r   rb   r)   r   r   r(   r%   r#   rm   rm      sU    S1 D% MQ%'%3I%	%N	X%r%   rm   c                   dfd}	 	 	 	 dfd}j                   s| S g }j                  }|j                  dk  s|j                  dk  r|S t	        j                               | D ]  }|j                         }j                  |      s&j                  |j                        r-j                  |j                        r|j                  |       nt        |t              rE ||j                        \  }	}
 ||	      |
z   }|st        |      |_        |j                  |       t        |t               rbj#                  |j$                  g      D ]@  }t!        |      }|j&                  |_        |j(                  |_        |j                  |       B 5t        |t*              rt-        |j.                        }|dk(  r|j                  |       r|dk(  ro|j.                  j1                         \  }}j3                  ||      D ];  }|st5        j4                  |      }t7        |      |_        |j                  |       = j9                  |j.                        D ]2  }|st5        j4                  |      }||_        |j                  |       4 8t        |t:              rxg }t=        |j>                  j1                               D ]-  \  }}j3                  ||      D ]  }|jA                  |        / t7        |      |_        |j                  |       t        |tB              rtE        d       |S )	z,Crop recorded shapes inplace by a rectangle.c                *   g }g }| D ]  }t        |j                               }j                  |      s.j                  |j                        r-j                  |j
                        r|j                  |       v|j                  |        ||fS r'   )r   rX   has_intersectioninsideextminextmaxry   )np_paths_inside_cropnp_pathr)   r   s        r#   
sort_pathsz%crop_records_rect.<locals>.sort_pathsf  s    %'#% 		&G !23D--d3!!$++.93C3CDKK3Pw'W%		& g~r%   c                :    t        j                  |             S r'   )listclip_filled_paths)r   clipperr   s    r#   
crop_pathsz%crop_records_rect.<locals>.crop_pathsw  s     G--hABBr%   g-q=r   r   zinvalid record type)r   rZ   )r   rZ   r0   zlist[NumpyPath2d])#r   sizexyr   r   r)   r   r   r   r   ry   r   rR   rT   r   rL   
clip_pathsrN   r   r    r:   rV   r=   r   	clip_liner   r   clip_polygonrF   r   rH   rW   r\   
ValueError)ri   r   r   r   r   cropped_recordsr   rz   
record_boxpaths_to_cropr   cropped_pathsppath_recordr   r   r   segment_recordpolygonr=   r   s    ``                  @r#   r   r   a  s   
"C'C	C (*O>>Dvv~%92245G 84[[]
))*5J--.93C3CJDUDU3V""6*f/0$.v||$<!M6&}5>M$]3&&v.
+''x@ 4(m,2,@,@)%+]]"&&{3	4
 -&Ez&&v.!}}--/1&00A6 4G" "ii/G%27%;GN#**734  '33FMMB 4G" "ii/G%,GN#**734  01!#Ffll3356 +1&00A6 +GMM'*++ )0FL""6*,
 233q84r r%   )ri   list[DataRecord]r   r   r   r   r0   r   )1
__future__r   typingr   r   r   r   r   r	   typing_extensionsr
   r   r   r7   
ezdxf.mathr   r   r   r   ezdxf.npshapesr   r   r   ezdxf.toolsr   ezdxf.tools.clipping_portalr   r   r   r   rg   r   rk   r   
type_hintsr   ABCr   r:   rF   rL   rR   r\   rd   r   r   r   rm   r   r(   r%   r#   <module>r      s    #  .  
 : : F F  4 0 ! )  ): )"(z ( ' ' &
 &"'* '$[ [|
z 
 #$5#6#@Ai As% s%l^^*7^CH^^r%   