
    Og,                        d dl mZ d dlmZm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mZ ddlmZ ddlmZ dd	lmZ  G d
 d      ZddZddZddZddZy)    )annotations)SequenceIteratorN   )Vec2PathNULLVEC2ConstructionCircleBezier4P)RGB
PropertiesFillType)Backend)PolygonBuffer)Pagec                     e Zd ZdZd-dZed.d       Zed.d       Zd/dZd0dZ	d1dZ
	 	 	 	 	 	 	 	 	 	 d2dZd3d	Zd4d
Z	 	 d5	 	 	 	 	 	 	 	 	 d6dZ	 	 	 	 	 	 	 	 	 	 d6dZd7dZd3dZd3dZd3dZd3dZd8dZd9dZd9dZd3dZd3dZd:dZd:dZd;dZd<dZd=dZd>dZd3dZ d?dZ!d3dZ"d@d Z#d@d!Z$d@d"Z%dAd#Z&dBd$Z'dCd%Z(dDd&Z)dDd'Z*dEd(Z+dEd)Z,dFd*Z-dFd+Z.y,)GPlottera  
    The :class:`Plotter` class represents a virtual plotter device.

    The HPGL/2 commands send by the :class:`Interpreter` are processed into simple
    polylines and filled polygons and send to low level :class:`Backend`.

    HPGL/2 uses a units system called "Plot Units":

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

    The Plotter device does not support font rendering and page rotation (RO).
    The scaling commands IP, RP, SC are supported.

    c                    || _         || _        t               | _        t	        dd      | _        t               | _        d| _        d| _	        d| _
        d| _        t        | _        g | _        y )Ni  iI  FT)backend_output_backendr   _polygon_bufferr   pager   
propertiesis_pen_downis_absolute_modeis_polygon_modehas_merge_controlr	   _user_location_pen_state_stack)selfr   s     _/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/addons/hpgl2/plotter.py__init__zPlotter.__init__%   sa    &,sO	$,  $$!&&,.    c                    | j                   S )zHReturns the current pen location as point in the user coordinate system.r   r    s    r!   user_locationzPlotter.user_location2   s     """r#   c                z    | j                   }| j                  j                  |j                  |j                        S )z@Returns the current pen location as page point in plotter units.)r'   r   
page_pointxyr    locations     r!   page_locationzPlotter.page_location7   s.     %%yy##HJJ

;;r#   c                &    t        ||      | _        y N)r   r   )r    size_xsize_ys      r!   
setup_pagezPlotter.setup_page=   s    (	r#   c                <    | j                   j                  ||       y r0   )r   set_scaling_points)r    p1p2s      r!   r5   zPlotter.set_scaling_points@   s    		$$R,r#   c                <    | j                   j                  ||       y r0   )r   set_scaling_points_relative_1)r    xp1yp1s      r!   r9   z%Plotter.set_scaling_points_relative_1C   s    		//S9r#   c                @    | j                   j                  ||||       y r0   )r   set_scaling_points_relative_2)r    r:   r;   xp2yp2s        r!   r=   z%Plotter.set_scaling_points_relative_2F   s     			//S#sCr#   c                8    | j                   j                          y r0   )r   reset_scalingr&   s    r!   rA   zPlotter.reset_scalingK   s    		!r#   c                >    | j                   j                  |||       y r0   )r   set_ucs)r    originscale_xscale_ys       r!   set_point_factorzPlotter.set_point_factorN   s    		&'73r#   c                D    | j                   j                  ||||||       y r0   )r   set_isotropic_scaling)r    x_minx_maxy_miny_maxleftbottoms          r!   rI   zPlotter.set_isotropic_scalingQ   s      			''ueUD&Qr#   c                @    | j                   j                  ||||       y r0   )r   set_anisotropic_scaling)r    rJ   rK   rL   rM   s        r!   rQ   zPlotter.set_anisotropic_scaling\   s     			))%uEr#   c                    || _         y r0   )r   r    statuss     r!   set_merge_controlzPlotter.set_merge_controla   s
    !'r#   c                    d| _         y NFr   r&   s    r!   pen_upzPlotter.pen_upd   s
     r#   c                    d| _         y NTrX   r&   s    r!   pen_downzPlotter.pen_downg   s
    r#   c                N    | j                   j                  | j                         y r0   )r   appendr   r&   s    r!   push_pen_statezPlotter.push_pen_statej   s    $$T%5%56r#   c                n    t        | j                        r | j                  j                         | _        y y r0   )lenr   popr   r&   s    r!   pop_pen_statezPlotter.pop_pen_statem   s,    t$$%#4488:D &r#   c                b    | j                   r| j                  |       y | j                  |       y r0   )r   move_to_absmove_to_relr,   s     r!   move_tozPlotter.move_toq   s'      X&X&r#   c                    || _         y r0   r%   r    r'   s     r!   re   zPlotter.move_to_absw   s
    +r#   c                .    | xj                   |z  c_         y r0   r%   ri   s     r!   rf   zPlotter.move_to_relz   s    },r#   c                    d| _         y r[   r   r&   s    r!   set_absolute_modezPlotter.set_absolute_mode}   s
     $r#   c                    d| _         y rW   rl   r&   s    r!   set_relative_modezPlotter.set_relative_mode   s
     %r#   c                :    | j                   j                  |       y r0   )r   set_current_penr    indexs     r!   rq   zPlotter.set_current_pen   s    ''.r#   c                :    | j                   j                  |       y r0   )r   set_max_pen_countrr   s     r!   ru   zPlotter.set_max_pen_count   s    ))%0r#   c                <    | j                   j                  ||       y r0   )r   set_pen_width)r    rs   widths      r!   rw   zPlotter.set_pen_width       %%eU3r#   c                <    | j                   j                  ||       y r0   )r   set_pen_color)r    rs   colors      r!   r{   zPlotter.set_pen_color   ry   r#   c                    |dv r$t        | j                  j                  |            }| j                  j	                  |||       y )N)      )maxr   scale_lengthr   set_fill_type)r    	fill_typespacingangles       r!   r   zPlotter.set_fill_type   s9    $))009:G%%i%@r#   c                    d| _         | j                  | _        |dk(  r&| j                  j                  | j                         y |dk(  r| j                  j                          y y )NTr   r   )r   r   r   resetr.   
close_pathrS   s     r!   enter_polygon_modezPlotter.enter_polygon_mode   sV    #++Q;  &&t'9'9:q[  ++- r#   c                h    d| _         | j                  j                          | j                  | _        y rW   )r   r   r   r   r   r&   s    r!   exit_polygon_modezPlotter.exit_polygon_mode   s)    $'')++r#   c                    | j                   j                  |       | j                  | j                  j	                                y r0   )r   set_fill_methodplot_filled_polygon_bufferr   	get_paths)r    fill_methods     r!   fill_polygonzPlotter.fill_polygon   s1    ''4''(<(<(F(F(HIr#   c                V    | j                  | j                  j                                y r0   )plot_outline_polygon_bufferr   r   r&   s    r!   edge_polygonzPlotter.edge_polygon   s    (()=)=)G)G)IJr#   c                h    |sy | j                   r| j                  |       y | j                  |       y r0   )r   plot_abs_polylineplot_rel_polyliner    pointss     r!   plot_polylinezPlotter.plot_polyline   s-      ""6*""6*r#   c                
   |sy | j                   }| j                  |d          | j                  rT| j                  j	                  |      }|j                  d|       | j                  j                  | j                  |       y y )Nr   )	r.   re   r   r   page_pointsinsertr   draw_polyliner   )r    r   current_page_locations      r!   r   zPlotter.plot_abs_polyline   so     $ 2 2$YY**62FMM!23LL&&t? r#   c                f    |sy | j                  t        t        | j                  |                   y r0   )r   tuplerel_to_abs_points_dynamicr'   r   s     r!   r   zPlotter.plot_rel_polyline   s,    +D,>,>GH	
r#   c                    | j                   rd| j                  }t        dd|      D cg c]  }|t        j                  ||      z    }}| j
                  j                  | j                  |       y y c c}w )Nr        v@)r   r'   
arc_anglesr   from_deg_angler   r   r   )r    radiuschord_anglecenteraverticess         r!   plot_abs_circlezPlotter.plot_abs_circle   st    ''F $Auk: ,,Q77H 
 LL&&tA s    A2c                   | j                   }||z
  }|j                  }|j                  }||z   }|t        j                  ||      z   }	| j                  |	       | j                  rXt        |||      D 
cg c]  }
|t        j                  |
|      z    }}
| j                  j                  | j                  |       y y c c}
w r0   )r'   	magnitude	angle_degr   r   re   r   r   r   r   r   )r    r   sweep_angler   start_point
radius_vecr   start_angle	end_angle	end_pointr   r   s               r!   plot_abs_arczPlotter.plot_abs_arc   s    (( 6)
%% **+-	T00FCC	# $KkJ ,,Q77H  LL&&tA s   4 B>c                D    | j                  || j                  z   ||       y r0   )r   r'   )r    
center_relr   r   s       r!   plot_rel_arczPlotter.plot_rel_arc   s    *t'9'99;Tr#   c                    | j                   }t        j                  |||      }|j                  }||z
  j                  }||z
  j                  }||z
  j                  }	t        ||	|      }
| j                  ||
|       y r0   )r'   r
   from_3pr   r   sweeping_angler   )r    interendr   startcircler   r   r   inter_angler   s              r!   plot_abs_arc_three_pointsz!Plotter.plot_abs_arc_three_points   sw    ""#++E5#>v~006\,,	v~00$[+yI&+{;r#   c                N    | j                   }| j                  ||z   ||z   |       y r0   )r'   r   )r    r   r   r   currents        r!   plot_rel_arc_three_pointsz!Plotter.plot_rel_arc_three_points   s'    $$&&w#{Sr#   c                *   | j                   }| j                  |       | j                  rj| j                  j	                  |||f      \  }}}t        |      }|j                  |||       | j                  j                  | j                  |gd       y y NFfilled)
r.   re   r   r   r   r   	curve4_tor   
draw_pathsr   )r    ctrl1ctrl2r   r   ps         r!   plot_abs_cubic_bezierzPlotter.plot_abs_cubic_bezier   s     $ 2 2 $		 5 5ueS6I JE5#*+AKKUE*LL##DOOaS#G r#   c                d    t        | j                  |||f      \  }}}| j                  |||       y r0   )rel_to_abs_points_staticr'   r   )r    r   r   r   s       r!   plot_rel_cubic_bezierzPlotter.plot_rel_cubic_bezier  s9    4s 3
uc 	""5%5r#   c                T    | j                   j                  | j                  |d       y )NTr   r   r   r   r    pathss     r!   r   z"Plotter.plot_filled_polygon_buffer  s    tDr#   c                T    | j                   j                  | j                  |d       y r   r   r   s     r!   r   z#Plotter.plot_outline_polygon_buffer  s    uEr#   N)r   r   returnNone)r   r   )r1   intr2   r   )r6   r   r7   r   r   r   )r:   floatr;   r   r   r   )
r:   r   r;   r   r>   r   r?   r   r   r   )r   r   )rD   r   rE   r   rF   r   r   r   )      ?r   )
rJ   r   rK   r   rL   r   rM   r   r   r   )rT   boolr   r   )r-   r   r   r   )r'   r   r   r   )rs   r   r   r   )rs   r   rx   r   r   r   )rs   r   r|   r   r   r   )r   r   r   r   r   r   r   r   )rT   r   r   r   )r   r   r   r   )r   Sequence[Vec2])r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   r   r   )r   zSequence[Path])/__name__
__module____qualname____doc__r"   propertyr'   r.   r3   r5   r9   r=   rA   rG   rI   rQ   rU   rY   r\   r_   rc   rg   re   rf   rm   ro   rq   ru   rw   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r#   r!   r   r      s    / # # < <
)-:DD$D+0D7<D	D
"4 	R	R 	R 		R
 	R 
	RFF#(F16F?DF	F
(! 7;',-%&/144A
.,
JK+@
	BB U	<T

H6EFr#   r   c              #  ,   K   |D ]  }| |z  } |   yw)zReturns the absolute location of increment points, each point is an increment
    of the previous point starting at the current pen location.
    Nr   r   r   points      r!   r   r     s&       5s   c              #  (   K   |D ]	  }| |z     yw)zpReturns the absolute location of increment points, all points are relative
    to the current pen location.
    Nr   r   s      r!   r   r     s!       os   c              #     K   t        dt        d|            }t        t        ||z              }||z  }t	        |dz         D ]  }| ||z  z     y w)Ng     f@r   r   )minr   absroundrange)r   r   r   countdeltars   s         r!   r   r   "  s^     eSk23KkK/01E%Euqy! $eem##$s   AAc                    | dz  } |dz  }|dz  }|| z
  }| |z
  }||z
  }t        j                  t        |      t        |      z   t        |            r|S |dk  rd|z   S |dz
  S )zaReturns the sweeping angle from start angle to end angle passing the
    intermediate angle.
    r   r   )mathiscloser   )r   intermediater   r   i_to_si_to_es         r!   r   r   +  s|     EME%'L
+C%KE\!F<F||CK#f+-s5z:195= 5= r#   )r   r   r   r   r   zIterator[Vec2])r   r   r   r   r   r   r   zIterator[float])r   r   r   r   r   r   r   r   )
__future__r   typingr   r   r   depsr   r   r	   r
   r   r   r   r   r   r   r   polygon_bufferr   r   r   r   r   r   r   r   r   r#   r!   <module>r      sN    # %   2 1  ) zF zFz$!r#   