
    hn{                    0   S SK Jr  S SKJrJrJrJrJr  S SKrS SK	J
r
Jr  S SKJr  S SKJr  S SKJr  SS	KJr  \(       a  S S
KJr  S SKJr  S SKJrJrJrJrJr  \R<                  " S5      rSS jr  " S S\5      r! " S S\!5      r" " S S\!5      r#SS jr$g)    )annotations)TYPE_CHECKINGAnyUnioncastOptionalN)Vec2UVec)EntitySpace)const)make_table_key   )
BaseLayout)Drawing)BlockLayout)GeoDataViewport	DXFLayout
DXFGraphicBlockRecordezdxfc                8    U R                   U   nUR                  $ N)entitydbentity_space)docblock_record_handleblock_records      F/var/www/html/env/lib/python3.13/site-packages/ezdxf/layouts/layout.pyget_block_entity_spacer       s    << 34L$$$    c                  F  ^  \ rS rSrSrSrSrSrSrSr	Sr
SrS	rS
rSrSrSrSrSrS1U 4S jjr\S2S3S jj5       r\S1S j5       r\S4S j5       r\S5S j5       r\S4S j5       rS6S jrS7S jrS6U 4S jjr\S8S j5       r S9 S6S jjrS:S6S jjr S;S<S jjr!S=S>S jjr"S4S jr#  S?     S@S jjr$SAS  jr%SBSCS! jjr&SBSCS" jjr'SBSCS# jjr(SBSCS$ jjr)SBSCS% jjr*SBSCS& jjr+SBSCS' jjr,SBSCS( jjr-SBSCS) jjr.SBSCS* jjr/SBSCS+ jjr0SBSCS, jjr1SBSCS- jjr2SBSCS. jjr3SBSCS/ jjr4S0r5U =r6$ )DLayout    a/  
Layout representation - base class for :class:`Modelspace` and
:class:`Paperspace`

Every layout consist of a LAYOUT entity in the OBJECTS section, an
associated BLOCK in the BLOCKS section and a BLOCK_RECORD_TABLE entry.

layout_key: handle of the BLOCK_RECORD, every layout entity has this
    handle as owner attribute (entity.dxf.owner)

There are 3 different layout types:

    1. :class:`Modelspace`
    2. active :class:`Paperspace` layout
    3. inactive :class:`Paperspace` layout

Internal Structure

For every layout exist a :class:`BlockLayout` object in
:class:`BlocksSection` and a :class:`Layout` object
(as :class:`Modelspace` or :class:`Paperspace`) in :class:`Layouts`.

The entity space of the :class:`BlockLayout` object and the entity space
of the :class:`Layout` object are the same object.

r               @      i   i   i   i   i    i @  c           	       > Xl         UR                  R                  SS5      n UR                  U   nUR                  5       S:w  aA  [        R                  " SU SUR                  R                   S	UR                  5        35      eUR                  R                  UR                  l        [        TU ]5  U5        g ! [         aB    [        U5      nUc1  [        R                  " SU SUR                  R                   S35      e Nf = f)
Nr   0zrequired BLOCK_RECORD #z for layout 'z' does not existBLOCK_RECORDzexpected BLOCK_RECORD(#z) for layout 'z' has invalid entity type: )
dxf_layoutdxfgetr   KeyError_find_layout_block_recordr   DXFStructureErrornamedxftypehandlelayoutsuper__init__)selfr7   r   r6   r   	__class__s        r   r9   Layout.__init__L   s     5s;	<</L !^3)))&

?P Q,,8,@,@,B+CE 
 #)**"3"3&  	4V<L#---fX]6::??BS T% &  $	s   B> >A	D
	D
c                    UR                   R                  U5      nU=(       d    0 nUR                  UUR                  S.5        UR                  R                  SUS9nU " Xc5      $ )a  Returns the required structures for a new layout:

    - a :class:`BlockLayout` with BLOCK_RECORD, BLOCK and ENDBLK entities
    - LAYOUT entity in the objects section

Args:
    name: layout name as shown in tabs of CAD applications e.g. 'Layout2'
    block_name: layout block name e.g. '*Paper_Space2'
    doc: drawing document
    dxfattribs: additional DXF attributes for LAYOUT entity

(internal API)

)r4   r   LAYOUT)
dxfattribs)blocksnewupdater   objects
new_entity)clsr4   
block_namer   r?   block_layoutr.   s          r   rA   
Layout.newa   se      %(JJNN:$>%2
'3'G'G	
 [[++H+L
:##r!   c                6    U " X5      nUR                  5         U$ )z!Loading interface. (internal API))_repair_owner_tags)rE   r7   r   _layouts       r   loadLayout.load|   s     f"""$r!   c                B    U R                   R                  R                  $ )z9Layout name as shown in tabs of :term:`CAD` applications.r.   r/   r4   r:   s    r   r4   Layout.name   s     ""'''r!   c                .    U R                   R                  $ )zReturns the DXF name space attribute of the associated
:class:`~ezdxf.entities.DXFLayout` object.

This enables direct access to the underlying LAYOUT entity,
e.g. ``Layout.dxf.layout_flags``

)r.   r/   rP   s    r   r/   
Layout.dxf   s     """r!   c                B    U R                   R                  R                  $ )z:Returns the name of the associated BLOCK_RECORD as string.)r   r/   r4   rP   s    r   block_record_nameLayout.block_record_name   s       $$)))r!   c                   U R                   nU R                  (       a  SOSnU  HY  nUR                  R                  U:w  a  XR                  l        UR                  R                  U:w  d  MI  X#R                  l        M[     g)z]Set `owner` and `paperspace` attributes of entities hosted by this
layout to correct values.
r   r   N)
layout_keyis_modelspacer/   owner
paperspace)r:   rX   r[   entitys       r   rJ   Layout._repair_owner_tags   s^     __
,,Q!
Fzz:-#-

 zz$$
2(2

%	 r!   c                    [        U[        5      (       a  U R                  U   nUR                  R                  U R
                  :H  $ )zReturns ``True`` if `entity` is stored in this layout.

Args:
     entity: :class:`DXFGraphic` object or handle as hex string

)
isinstancestrr   r/   rZ   rX   )r:   r\   s     r   __contains__Layout.__contains__   s8     fc""]]6*Fzz4??22r!   c                   > U R                   R                  R                  U R                  5        [        TU ]  5         g)zjDelete all entities and the layout itself from entity database and
all linked structures.

(internal API)
N)r   rC   delete_entityr.   r8   destroy)r:   r;   s    r   re   Layout.destroy   s+     	&&t7r!   c                B    U R                   R                  R                  $ r   )r.   r/   plot_layout_flagsrP   s    r   rh   Layout.plot_layout_flags   s    ""444r!   c                H    U R                   R                  nXl        X#l        g)a<  Reset `extents`_ to given values or the AutoCAD default values.

"Drawing extents are the bounds of the area occupied by objects."
(Quote Autodesk Knowledge Network)

Args:
     extmin: minimum extents or (+1e20, +1e20, +1e20) as default value
     extmax: maximum extents or (-1e20, -1e20, -1e20) as default value

N)r.   r/   extminextmax)r:   rk   rl   r/   s       r   reset_extentsLayout.reset_extents   s     oo!!

r!   c                    U R                   R                  nUc  SnUc  UR                  UR                  4nXl        X#l        g)a  Reset `limits`_ to given values or the AutoCAD default values.

"Sets an invisible rectangular boundary in the drawing area that can
limit the grid display and limit clicking or entering point locations."
(Quote Autodesk Knowledge Network)

The :class:`Paperspace` class has an additional method
:meth:`~Paperspace.reset_paper_limits` to deduce the default limits from
the paper size settings.

Args:
     limmin: minimum limits or (0, 0) as default
     limmax: maximum limits or (paper width, paper height) as default value

Nr   r   )r.   r/   paper_widthpaper_heightlimminlimmax)r:   rs   rt   r/   s       r   reset_limitsLayout.reset_limits   s@      oo!!>F>oos'7'78F

r!   c                    S[        U5      s=::  a  S::  a  O  OXR                  l        g[        R                  " S5      e)a  
=== ============================================================
0   last screen display
1   drawing extents
2   drawing limits
3   view specific (defined by :attr:`Layout.dxf.plot_view_name`)
4   window specific (defined by :meth:`Layout.set_plot_window_limits`)
5   layout information (default)
=== ============================================================

Args:
    value:  plot type

Raises:
    DXFValueError: for `value` out of range

r      z#Plot type value out of range (0-5).N)intr/   	plot_typer   DXFValueError)r:   values     r   set_plot_typeLayout.set_plot_type   s1    $ E
a!&HH%%&KLLr!   c                |    XR                   R                  l        U R                  S5        U R	                  U5        g)zSet plot style file of type `.ctb`.

Args:
    name: plot style filename
    show: show plot style effect in preview? (AutoCAD specific attribute)

TN)r.   r/   current_style_sheetuse_plot_stylesshow_plot_styles)r:   r4   shows      r   set_plot_styleLayout.set_plot_style   s0     37/T"d#r!   c                B    U R                   R                  R                  $ r   )r.   r/   r   rP   s    r   get_plot_style_filenameLayout.get_plot_style_filename  s    ""666r!   c                    Uu  p4Uu  pVU R                   R                  nX7l        XGl        XWl        Xgl        U R                  S5        g)zSet plot window size in (scaled) paper space units.

Args:
    lower_left: lower left corner as 2D point
    upper_right: upper right corner as 2D point

r&   N)r.   r/   plot_window_x1plot_window_y1plot_window_x2plot_window_y2r}   )r:   
lower_leftupper_rightx1y1x2y2r/   s           r   set_plot_windowLayout.set_plot_window  sG     oo!!1r!   c                    U R                   R                  nU R                   R                  nSnU(       a  X!-  nU R                   R                  S:X  a  U$ US-  $ )N      ?r   ffffff9@)r/   scale_denominatorscale_numeratorplot_paper_units)r:   denom	numeratorscales       r   get_plot_unit_scale_factor!Layout.get_plot_unit_scale_factor#  sQ    **HH,,	%E88$$)L4<r!   c                <    U R                  U R                  U5        g r   )set_plot_flagsPLOT_VIEWPORT_BORDERSr:   states     r   plot_viewport_bordersLayout.plot_viewport_borders/  s    D66>r!   c                <    U R                  U R                  U5        g r   )r   SHOW_PLOT_STYLESr   s     r   r   Layout.show_plot_styles2  s    D1159r!   c                <    U R                  U R                  U5        g r   )r   PLOT_CENTEREDr   s     r   plot_centeredLayout.plot_centered5  s    D..6r!   c                <    U R                  U R                  U5        g r   )r   PLOT_HIDDENr   s     r   plot_hiddenLayout.plot_hidden8  s    D,,e4r!   c                <    U R                  U R                  U5        g r   )r   USE_STANDARD_SCALEr   s     r   use_standard_scaleLayout.use_standard_scale;  s    D33U;r!   c                <    U R                  U R                  U5        g r   )r   PLOT_PLOTSTYLESr   s     r   r   Layout.use_plot_styles>  s    D00%8r!   c                <    U R                  U R                  U5        g r   )r   SCALE_LINEWEIGHTSr   s     r   scale_lineweightsLayout.scale_lineweightsA      D22E:r!   c                <    U R                  U R                  U5        g r   )r   PRINT_LINEWEIGHTSr   s     r   print_lineweightsLayout.print_lineweightsD  r   r!   c                <    U R                  U R                  U5        g r   )r   DRAW_VIEWPORTS_FIRSTr   s     r   draw_viewports_firstLayout.draw_viewports_firstG  s    D55u=r!   c                <    U R                  U R                  U5        g r   )r   
MODEL_TYPEr   s     r   
model_typeLayout.model_typeJ  s    DOOU3r!   c                <    U R                  U R                  U5        g r   )r   UPDATE_PAPERr   s     r   update_paperLayout.update_paperM      D--u5r!   c                <    U R                  U R                  U5        g r   )r   ZOOM_TO_PAPER_ON_UPDATEr   s     r   zoom_to_paper_on_updateLayout.zoom_to_paper_on_updateP  s    D88%@r!   c                <    U R                  U R                  U5        g r   )r   INITIALIZINGr   s     r   plot_flags_initializingLayout.plot_flags_initializingS  r   r!   c                <    U R                  U R                  U5        g r   )r   PREV_PLOT_INITr   s     r   prev_plot_initLayout.prev_plot_initV  s    D//7r!   c                8    U R                   R                  XSS9  g )Nrh   )r   r4   )r.   set_flag_state)r:   flagr   s      r   r   Layout.set_plot_flagsY  s    &&t?R&Sr!   )r.   )r7   r   r   r   r   )r4   r`   rF   r`   r   r   returnr#   r   r`   )r   r   r   None)r\   zUnion[DXFGraphic, str]r   bool)r   ry   ))@xDr   r   )@xr   r   NN)rx   )r|   ry   r   r   )z	ezdxf.ctbF)r4   r`   r   r   r   r   )rp   rp   )r   tuple[float, float]r   r   r   r   )r   float)T)r   r   r   r   )7__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r9   classmethodrA   rL   propertyr4   r/   rU   rJ   ra   re   rh   rm   ru   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes____classcell__)r;   s   @r   r#   r#       s   8 MKOJL"LN'* $ $4   ( ( # # * *
3	3	 5 5 4I	"2M.
$7
 +1+1' ) 
	*	 ?:75<9;;>46A68T Tr!   r#   c                  D    \ rS rSrSr\SS j5       rS	S
S jjrSS jrSr	g)
Modelspacei]  z:class:`Modelspace` - not deletable, all entities of this layout are
stored in the ENTITIES section of the DXF file, the associated
"*Model_Space" block is empty, block name is fixed as "*Model_Space",
the name is fixed as "Model".

c                    g)z'Name of modelspace is fixed as "Model".Model rP   s    r   r4   Modelspace.namee  s     r!   Nc                8   U R                   R                  [        R                  :  a  [        R                  " S5      eUc  0 nU R                  5       nU R                   R                  R                  UR                  R                  R                  US9nX2S'   U$ )a1  Creates a new :class:`GeoData` entity and replaces existing ones.
The GEODATA entity resides in the OBJECTS section and not in the
modelspace, it is linked to the modelspace by an
:class:`~ezdxf.entities.ExtensionDict` located in BLOCK_RECORD of the
modelspace.

The GEODATA entity requires DXF R2010. The DXF reference does not
document if other layouts than the modelspace supports geo referencing,
so I assume getting/setting geo data may only make sense for the
modelspace.

Args:
    dxfattribs: DXF attributes for :class:`~ezdxf.entities.GeoData` entity

z+GEODATA entity requires DXF R2010 or later.)rZ   r?   ACAD_GEOGRAPHICDATA)r   
dxfversionr   DXF2010r{   get_extension_dictrC   add_geodata
dictionaryr/   r6   )r:   r?   xdictgeodatas       r   new_geodataModelspace.new_geodataj  s      88.%%&STTJ'')((""..""&&--! / 
 (/#$r!   c                     U R                   R                  5       n US   $ ! [         a     gf = f! [        R                   a     gf = f)z^Returns the :class:`~ezdxf.entities.GeoData` entity associated to
the modelspace or ``None``.
Nr   )r   r   AttributeErrorr   DXFKeyError)r:   r   s     r   get_geodataModelspace.get_geodata  sY    	%%88:E	.//  		    		s   " 2 
//A	A	r   r   r   )r   r   )r   zOptional[GeoData])
r   r   r   r   r   r   r4   r  r  r   r   r!   r   r   r   ]  s%      :r!   r   c                  0   \ rS rSrSrSS jrSS jrSS jr  S           SS jjrS r	SS	 jr
SSS
 jjr  SS jrSS jrSS jr        S                 S S jjrSS jrS!S jr      S"             S#S jjrS!S jrSrg)$
Paperspacei  a  There are two kind of paperspace layouts:

1. Active Layout - all entities of this layout are stored in the ENTITIES
   section, the associated "*Paper_Space" block is empty, block name
   "*Paper_Space" is mandatory and also marks the active layout, the layout
   name can be an arbitrary string.

2. Inactive Layout - all entities of this layouts are stored in the
   associated BLOCK called "*Paper_SpaceN", where "N" is an arbitrary
   number, I don't know if the block name schema "*Paper_SpaceN" is
   mandatory, the layout name can be an arbitrary string.

There is no different handling for active layouts and inactive layouts in
`ezdxf`, this differentiation is just for AutoCAD important and it is not
documented in the DXF reference.

c                8    XR                   R                  l        g)zRename layout to `name`, changes the name displayed in tabs by
CAD applications, not the internal BLOCK name. (internal API)

Use method :meth:`~ezdxf.layouts.Layouts.rename` of the
:meth:`~ezdxf.layouts.Layouts` class to rename paper space
layouts.

NrO   )r:   r4   s     r   renamePaperspace.rename  s     $( r!   c                    U  Vs/ s H-  oR                   (       d  M  UR                  5       S:X  d  M+  UPM/     sn$ s  snf )z<Get all VIEWPORT entities defined in this paperspace layout.VIEWPORT)is_aliver5   )r:   es     r   	viewportsPaperspace.viewports  s-    L4a::!))+2K4LLLs   <<<c                    U R                  5        HM  nUR                  nUR                  S5      (       a  UR                  S:X  a  Us  $ UR                  S:X  d  MK  Us  $    g)z^Returns the main viewport of this paper space layout, or ``None``
if no main viewport exist.

statusr   N)r  r/   hasattrr  id)r:   viewportr/   s      r   main_viewportPaperspace.main_viewport  sQ     (H,,C{{8$$qvv{ ) r!   Nc                    U=(       d    0 nUu  pxUUUUSUUS.n	U	R                  U5        [        SU R                  SU	5      5      n
U R                  5       U
R                  l        U
$ )a  Add a new :class:`~ezdxf.entities.Viewport` entity.

Viewport :attr:`status`:

    - -1 is on, but is fully off-screen, or is one of the viewports that is not
      active because the $MAXACTVP count is currently being exceeded.
    - 0 is off
    - any value>0 is on and active. The value indicates the order of
      stacking for the viewports, where 1 is the "active viewport", 2 is the
      next, ...

	VIEWPORTS)centerwidthheightr  layerview_center_pointview_heightr   r  )rB   r   rD   get_next_viewport_idr/   r  )r:   r  sizer!  r"  r  r?   r  r  attribsr  s              r   add_viewportPaperspace.add_viewport  so    *  %2
 !2&	
 	z"
DOOJ$HI335r!   c                \    U R                  5       nU(       a  [        S U 5       5      S-   $ g)Nc              3  L   #    U  H  oR                   R                  v   M     g 7fr   )r/   r  ).0vps     r   	<genexpr>2Paperspace.get_next_viewport_id.<locals>.<genexpr>  s     59Rvvyy9s   "$r   r%   )r  max)r:   r  s     r   r#  Paperspace.get_next_viewport_id  s*    NN$	595599r!   c                t    U R                  5        H  nU R                  U5        M     U R                  5         g)z>Delete all existing viewports, and create a new main viewport.N)r  rd   add_new_main_viewport)r:   r  s     r   reset_viewportsPaperspace.reset_viewports  s/     (Hx( )""$r!   c                    U R                  5       nUc  U R                  5       nU R                  5       u  pEUc  UnUc  UnXR                  l        Uu  pgXcR                  l        XsR                  l        U$ )a  Reset the main viewport of this paper space layout to the given
values, or reset them to the default values, deduced from the paper
settings. Creates a new main viewport if none exist.

Ezdxf does not create a main viewport by default, because CAD
applications don't require one.

Args:
    center: center of the viewport in paper space units
    size: viewport size as (width, height) tuple in paper space units

)r  r1  default_viewport_configr/   r  r  r  )r:   r  r$  r  default_centerdefault_sizer  r  s           r   reset_main_viewportPaperspace.reset_main_viewport  su     %%'113H'+'C'C'E$>#F<D$"$r!   c                  ^^ U R                   R                  nUR                  S:X  a  SmOSmUR                  UR                  -  mUU4S jnU" UR
                  5      nU" UR                  5      nU" UR                  5      nU" UR                  5      nX2" UR                  5      -
  U" UR                  5      -
  nXB" UR                  5      -
  U" UR                  5      -
  nUS-  n	US-  n
US-  U-
  US-  U-
  4nXU
44$ )Nr   r   r   c                   > U T-  T-  $ r   r   )r|   scale_factorunit_factors    r   paper_units7Paperspace.default_viewport_config.<locals>.paper_units"  s    ;&55r!   皙?r%   )r.   r/   r   r   r   rq   rr   plot_origin_x_offsetplot_origin_y_offsetleft_marginright_marginbottom_margin
top_margin)r:   r/   r>  rq   rr   x_offsety_offsetprintable_widthprintable_heightvp_width	vp_heightr  r<  r=  s               @@r   r5  "Paperspace.default_viewport_config  s"    oo!!1$KK ,,s/B/BB	6 "#//2"3#3#34s778s778 +coo66SEUEU9VV 	 ;s'8'899K<WW 	
 $ 3&	 a(*q 8+
 ),,,r!   c                   U R                  5       u  pUS   nU R                  UUUUSS9n[        U R                  5      S:  a<  U R                  R	                  5       nXTL d   eU R                  R                  SU5        SUR                  l        SUR                  l        U R                  UR                  R                  5        U$ )zAdd a new main viewport.r   r  r$  r!  r"  r  r   i  )r5  r&  lenr   popinsertr/   r  flagsset_current_viewport_handler6   )r:   r  r$  rL  r  _vps         r   r1   Paperspace.add_new_main_viewport>  s    335G	))$! * 
 t  !A%##'')C'''$$Q6 "((():):)A)ABr!   c                8    XR                   R                  l        g r   )r.   r/   viewport_handle)r:   r6   s     r   rT  &Paperspace.set_current_viewport_handleU  s    .4+r!   c	                   [        U5      S;  a  [        R                  " S5      e[        U[        5      (       a  Sn	Uu  pOP[        U[         5      (       a%  Un	[        R
                  R                  U	S5      u  pO[        R                  " S5      eU
S:X  a  [        R                  " S5      eUS:X  a  [        R                  " S5      eUu  pUu  pnnUR                  5       nUR                  S	5      (       a  S
nSnSnO#US:X  a  SnSnSnO[        R                  " S5      eU R                  R                  nUR                  S5      (       d  UR                  S5      Ul        U R                  S5        SUl        UUl        U SUS SUS SU S3Ul        UU-  Ul        UU-  Ul        UU-  Ul        UU-  Ul        UU-  Ul        UU-  Ul        U
Ul        UUl        UUl        UUl        Uu  nnUU-  Ul        UU-  Ul        U	Ul        SU-  Ul         U RC                  5         U RE                  5         U RG                  5         g)a  Setup plot settings and paper size and reset viewports.
All parameters in given `units` (mm or inch).

Reset paper limits, extents and viewports.

Args:
    size: paper size as (width, height) tuple
    margins: (top, right, bottom, left) hint: clockwise
    units: "mm" or "inch"
    offset: plot origin offset is 2D point
    rotation: see table Rotation
    scale: integer in range [0, 32] defines a standard scale type or
        as tuple(numerator, denominator) e.g. (1, 50) for scale 1:50
    name: paper name prefix "{name}_({width}_x_{height}_{unit})"
    device: device .pc3 configuration file or system printer name

=== ============
int Rotation
=== ============
0   no rotation
1   90 degrees counter-clockwise
2   upside-down
3   90 degrees clockwise
=== ============

r   r   r%      zvalid rotation values: 0-3r(   )r   r   z9Scale has to be an int or a tuple(numerator, denominator)r   Scale numerator can't be 0.Scale denominator can't be 0.inchInchesr   mmMMr   r    Supported units: "mm" and "inch"rh   F z_(z.2f_x__)N)$ry   r   r{   r_   tuple
STD_SCALESr0   DXFTypeErrorlower
startswithr.   r/   r  get_defaultrh   r   page_setup_nameplot_configuration_file
paper_sizerC  rE  rD  rF  rq   rr   r   r   r   plot_rotationrA  rB  standard_scale_typer=  reset_paper_limitsrm   r2  )r:   r$  marginsunitsoffsetrotationr   r4   devicestandard_scale	scale_numscale_denomrq   rr   
margin_topmargin_rightmargin_bottommargin_leftr   r=  r/   rG  rH  s                          r   
page_setupPaperspace.page_setupX  sc   J x=,%%&BCCeU##N%*"I{s##"N%*%5%5%9%9.*%U"I{$$K  >%%&CDD!%%&EFF$(!?F<
-F##E Kd]E K%%&HII oo!!{{.//$'OO4G$HC!& &,# 6K#4CS7I5'QRS%3)K7'+5#k1%3'+5' +/$#(#+k#9 #+k#9 "0+ 	!r!   c                N   U R                   R                  nUR                  S:X  a  SnOSnUR                  U-  nUR                  U-  nUR
                  U-  nUR                  U-  nUR                  U-  nUR                  U-  nXW-   n	Xh-   n
U	* U
* 4Ul	        X9-
  XJ-
  4Ul
        g)z`Set paper limits to default values, all values in paperspace units
but without plot scale (?).

r   r   r   N)r.   r/   r   rq   rr   rC  rE  rA  rB  rs   rt   )r:   r/   r=  rq   rr   rC  rE  rG  rH  shift_xshift_ys              r   rs  Paperspace.reset_paper_limits  s    
 oo!!1$KK oo3''+5oo3))K7++k9++k9 (*h)
!+\-CD
r!   c                ~    [        U R                  R                  5      [        U R                  R                  5      4$ )a  Returns paper limits in plot paper units, relative to the plot origin.

plot origin = lower left corner of printable area + plot origin offset

Returns:
    tuple (Vec2(x1, y1), Vec2(x2, y2)), lower left corner is (x1, y1),
    upper right corner is (x2, y2).

)r	   r/   rs   rt   rP   s    r   get_paper_limitsPaperspace.get_paper_limits  s)     DHHOO$d488??&;;;r!   c                H  ^ U R                  5        H  nU R                  U5        M     [        U5      S;  a  [        R                  " S5      e[        U[        5      (       a#  [        R                  R                  US5      u  pOUu  pUS:X  a  [        R                  " S5      eU	S:X  a  [        R                  " S5      eX-  mUR                  5       nUR                  S5      (       a  SnSn
S	nO#US
:X  a  SnSn
SnO[        R                  " S5      eU4S jnU" US   5      nU" US   5      nU" US   5      nU" US   5      nU" US   5      nU" US   5      nSU R                  R                  S'   UU4U R                  R                  S'   SU R                  R                  S'   UUS4U R                  R                  S'   UU-
  U-
  nUU-
  U-
  nUS-  nUS-  nUS-  US-  4nU R                  UUU4UUSS9nSUR                  l        SUR                  l        g )Nr[  zValid rotation values: 0-3)r   r   r   r]  r^  r_  r`  r   ra  rb  r   r   rc  c                   > U T-  $ r   r   )r|   r<  s    r   r>  .Paperspace.page_setup_r12.<locals>.paper_units
  s    <''r!   r%   r\  rp   $PLIMMIN$PLIMMAX)r   r   r   z$PEXTMINz$PEXTMAXr@  rO  i  )r  rd   ry   r   r{   r_   ri  r0   rk  rl  r   headerr&  r/   r  render_mode)r:   r$  rt  ru  rv  rw  r   r  rz  r{  r   r=  r>  r|  r}  r~  r  rq   rr   rI  rJ  rK  rL  r  r  r<  s                            @r   page_setup_r12Paperspace.page_setup_r12  sN    (Hx( ) x=,%%&BCCeS!!%*%5%5%9%9%%H"I{%*"I>%%&CDD!%%&EFF". F##E Kd]E K%%&HII	( !,
"71:.#GAJ/!'!*-!$q'*"47+&,
#'2L&A
#&/
#'2L!&D
# &3lB'-7*D $ 3&	 "A%'7!';< ))I&$! * 
  !(,%r!   c                    U R                   R                  R                  SS5      nU R                   R                  R                  SS5      n[        U5      [        U5      4$ )z)Returns paper limits in plot paper units.r  rp   r  )r   r  r0   r	   )r:   rs   rt   s      r   get_paper_limits_r12Paperspace.get_paper_limits_r12.  sI    $$Z8$$Z8F|T&\))r!   r   )r4   r`   r   r   )r   zlist[Viewport])r   zOptional[Viewport])r%   N)r  r
   r$  r   r!  r
   r"  r   r  ry   r   r   r   r   )r  r
   r$  r
   r   r   )r   z/tuple[tuple[float, float], tuple[float, float]])r   r   )r6   r`   r   r   )i)     r   r   r   r   ra  rp   r   r(   r   zDWG to PDF.pc3)r$  r   rt  !tuple[float, float, float, float]ru  r`   rv  r   rw  ry   r   Union[int, tuple[float, float]]r4   r`   rx  r`   r   r   )r   ztuple[Vec2, Vec2])r  r  ra  rp   r   r(   )r$  r   rt  r  ru  r`   rv  r   rw  r   r   r  r   r   )r   r   r   r   r   r  r  r  r&  r#  r2  r8  r5  r1  rT  r  rs  r  r  r  r   r   r!   r   r
  r
    s~   $	(M* $$ "$  	$
 $ $ 
$L%8'-	8'-R.5
 %/5A&,13&a!a 3a 	a
 $a a /a a a 
aFE2
< %/5A&,13L-!L- 3L- 	L-
 $L- L- /L- 
L-\*r!   r
  c                2  ^ ^^^ SU 4S jjmT R                   mTc   eT R                  R                  S:X  aX  [        S5      nTR                  R
                   H2  n[        UR                  R                  5      U:X  d  M(  T" U5        Us  $    g[        S5      nTR                  R
                   Vs/ s H:  n[        UR                  R                  5      R                  U5      (       d  M8  UPM<     snmUUU4S jnU" T 5      nUc  U" S5      nU$ s  snf )z@Find and link the lost BLOCK_RECORD for the given LAYOUT entity.c           
     "  > [         R                  STR                  R                   S[	        T5       S[	        U 5       35        U R                  R
                  TR                  l        TR                  R
                  U R                  l        g )Nzfixing broken links for 'z
' between z and )loggerinfor/   r4   r`   r6   r   r7   )r   r7   s    r   link_layout._find_layout_block_record.<locals>.link_layout8  sl    '

'8
3v;-uUXYeUfTgh	
 *6)9)9)@)@

&"(**"3"3r!   Nr   z*Model_Spacez*Paper_Spacec                   > T HI  nUR                   R                  SS5      nTR                  R                  U5      U L d  M?  T" U5        Us  $    g )Nr7   r,   )r/   r0   r   )keyr   layout_handler   r  paper_space_recordss      r   search)_find_layout_block_record.<locals>.searchQ  sO    /L(,,003?M||.#5L)##	 0
 r!   )r   r   r   r   )r   r/   r4   r   tablesblock_recordsrl  )r7   r  r   
search_keyr  r   r  r  s   `    @@@r   r2   r2   5  s    4 **C??zz'!^,JJ44Ll..334;L)## 5   /J  JJ444L,**//0;;JG 	4 &>Ld|'s   37D.D)r   r   r   r`   r   r   )r7   r   r   zBlockRecord | None)%
__future__r   typingr   r   r   r   r   logging
ezdxf.mathr	   r
   ezdxf.entitydbr   ezdxf.lldxfr   ezdxf.lldxf.validatorr   baser   ezdxf.documentr   ezdxf.layoutsr   ezdxf.entitiesr   r   r   r   r   	getLoggerr  r    r#   r   r
  r2   r   r!   r   <module>r     s~    #   ! &  0 &)TT			7	#%
zTZ zTz	5 5p]* ]*@)r!   