
    Ogn{                    "   d dl mZ d dlmZmZmZmZmZ d dlZd dl	m
Z
mZ d dlmZ d dlmZ d dlmZ dd	lmZ erd d
lmZ d dlmZ d dlmZmZmZmZmZ  ej<                  d      ZddZ  G d de      Z! G d de!      Z" G d de!      Z#ddZ$y)    )annotations)TYPE_CHECKINGAnyUnioncastOptionalN)Vec2UVec)EntitySpace)const)make_table_key   )
BaseLayout)Drawing)BlockLayout)GeoDataViewport	DXFLayout
DXFGraphicBlockRecordezdxfc                8    | j                   |   }|j                  S N)entitydbentity_space)docblock_record_handleblock_records      Y/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/layouts/layout.pyget_block_entity_spacer       s    << 34L$$$    c                      e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZd0 fdZed1d2d       Zed0d       Zed3d       Zed4d       Zed3d       Zd5dZd6dZd5 fdZed7d       Z	 d8	 d5dZd9d5dZd:d;dZ d<d=dZ!d3dZ"	 	 d>	 	 	 	 	 d?dZ#d@d Z$dAdBd!Z%dAdBd"Z&dAdBd#Z'dAdBd$Z(dAdBd%Z)dAdBd&Z*dAdBd'Z+dAdBd(Z,dAdBd)Z-dAdBd*Z.dAdBd+Z/dAdBd,Z0dAdBd-Z1dAdBd.Z2dAdBd/Z3 xZ4S )CLayoutas  
    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           	        || _         |j                  j                  dd      }	 |j                  |   }|j                         dk7  r@t        j                  d| d|j                  j                   d	|j                                |j                  j                  |j                  _        t        | 5  |       y # t        $ r@ t        |      }|0t        j                  d| d|j                  j                   d      Y w xY w)
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   z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                    |j                   j                  |      }|xs i }|j                  ||j                  d       |j                  j                  d|      } | ||      S )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   r@   z
Layout.newa   sg      %(JJNN:$>%2
'3'G'G	
 [[++H+L
:s##r!   c                8     | ||      }|j                          |S )z!Loading interface. (internal API))_repair_owner_tags)rD   r7   r   _layouts       r   loadzLayout.load|   s!     fc"""$r!   c                B    | j                   j                  j                  S )z9Layout name as shown in tabs of :term:`CAD` applications.r.   r/   r4   r:   s    r   r4   zLayout.name   s     ""'''r!   c                .    | j                   j                  S )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/   rM   s    r   r/   z
Layout.dxf   s     """r!   c                B    | j                   j                  j                  S )z:Returns the name of the associated BLOCK_RECORD as string.)r   r/   r4   rM   s    r   block_record_namezLayout.block_record_name   s       $$)))r!   c                    | j                   }| j                  rdnd}| D ]W  }|j                  j                  |k7  r||j                  _        |j                  j                  |k7  sG||j                  _        Y y)zmSet `owner` and `paperspace` attributes of entities hosted by this
        layout to correct values.
        r   r   N)
layout_keyis_modelspacer/   owner
paperspace)r:   rR   rU   entitys       r   rH   zLayout._repair_owner_tags   sg     __
,,Q!
 	3Fzz:-#-

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

%		3r!   c                    t        |t              r| j                  |   }|j                  j                  | j
                  k(  S )zReturns ``True`` if `entity` is stored in this layout.

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

        )
isinstancestrr   r/   rT   rR   )r:   rV   s     r   __contains__zLayout.__contains__   s5     fc"]]6*Fzz4??22r!   c                    | j                   j                  j                  | j                         t        |           y)zDelete all entities and the layout itself from entity database and
        all linked structures.

        (internal API)
        N)r   rB   delete_entityr.   r8   destroy)r:   r;   s    r   r]   zLayout.destroy   s+     	&&t7r!   c                B    | j                   j                  j                  S r   )r.   r/   plot_layout_flagsrM   s    r   r_   zLayout.plot_layout_flags   s    ""444r!   c                L    | j                   j                  }||_        ||_        y)al  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:   ra   rb   r/   s       r   reset_extentszLayout.reset_extents   s!     oo!!

r!   c                    | j                   j                  }|d}||j                  |j                  f}||_        ||_        y)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:   rh   ri   r/   s       r   reset_limitszLayout.reset_limits   sD      oo!!>F>oos'7'78F

r!   c                ~    dt        |      cxk  rdk  rn n|| j                  _        yt        j                  d      )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_typezLayout.set_plot_type   s3    $ E
a!&DHH%%&KLLr!   c                ~    || j                   j                  _        | j                  d       | j	                  |       y)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_stylezLayout.set_plot_style   s2     37/T"d#r!   c                B    | j                   j                  j                  S r   )r.   r/   rs   rM   s    r   get_plot_style_filenamezLayout.get_plot_style_filename  s    ""666r!   c                    |\  }}|\  }}| j                   j                  }||_        ||_        ||_        ||_        | j                  d       y)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_y2rq   )r:   
lower_leftupper_rightx1y1x2y2r/   s           r   set_plot_windowzLayout.set_plot_window  sS     BBoo!!1r!   c                    | j                   j                  }| j                   j                  }d}|r||z  }| j                   j                  dk(  r|S |dz  S )N      ?r   ffffff9@)r/   scale_denominatorscale_numeratorplot_paper_units)r:   denom	numeratorscales       r   get_plot_unit_scale_factorz!Layout.get_plot_unit_scale_factor#  sS    **HH,,	%E88$$)L4<r!   c                <    | j                  | j                  |       y r   )set_plot_flagsPLOT_VIEWPORT_BORDERSr:   states     r   plot_viewport_borderszLayout.plot_viewport_borders/  s    D66>r!   c                <    | j                  | j                  |       y r   )r   SHOW_PLOT_STYLESr   s     r   ru   zLayout.show_plot_styles2  s    D1159r!   c                <    | j                  | j                  |       y r   )r   PLOT_CENTEREDr   s     r   plot_centeredzLayout.plot_centered5  s    D..6r!   c                <    | j                  | j                  |       y r   )r   PLOT_HIDDENr   s     r   plot_hiddenzLayout.plot_hidden8  s    D,,e4r!   c                <    | j                  | j                  |       y r   )r   USE_STANDARD_SCALEr   s     r   use_standard_scalezLayout.use_standard_scale;  s    D33U;r!   c                <    | j                  | j                  |       y r   )r   PLOT_PLOTSTYLESr   s     r   rt   zLayout.use_plot_styles>  s    D00%8r!   c                <    | j                  | j                  |       y r   )r   SCALE_LINEWEIGHTSr   s     r   scale_lineweightszLayout.scale_lineweightsA      D22E:r!   c                <    | j                  | j                  |       y r   )r   PRINT_LINEWEIGHTSr   s     r   print_lineweightszLayout.print_lineweightsD  r   r!   c                <    | j                  | j                  |       y r   )r   DRAW_VIEWPORTS_FIRSTr   s     r   draw_viewports_firstzLayout.draw_viewports_firstG  s    D55u=r!   c                <    | j                  | j                  |       y r   )r   
MODEL_TYPEr   s     r   
model_typezLayout.model_typeJ  s    DOOU3r!   c                <    | j                  | j                  |       y r   )r   UPDATE_PAPERr   s     r   update_paperzLayout.update_paperM      D--u5r!   c                <    | j                  | j                  |       y r   )r   ZOOM_TO_PAPER_ON_UPDATEr   s     r   zoom_to_paper_on_updatezLayout.zoom_to_paper_on_updateP  s    D88%@r!   c                <    | j                  | j                  |       y r   )r   INITIALIZINGr   s     r   plot_flags_initializingzLayout.plot_flags_initializingS  r   r!   c                <    | j                  | j                  |       y r   )r   PREV_PLOT_INITr   s     r   prev_plot_initzLayout.prev_plot_initV  s    D//7r!   c                @    | j                   j                  ||d       y )Nr_   )r   r4   )r.   set_flag_state)r:   flagr   s      r   r   zLayout.set_plot_flagsY  s    &&t5?R&Sr!   )r7   r   r   r   r   )r4   rY   rE   rY   r   r   returnr#   r   rY   )r   r   r   None)rV   zUnion[DXFGraphic, str]r   bool)r   rm   ))@xDr   r   )@xr   r   NN)rl   )rp   rm   r   r   )z	ezdxf.ctbF)r4   rY   rv   r   r   r   )re   re   )r   tuple[float, float]r   r   r   r   )r   float)T)r   r   r   r   )5__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r   r   r   r   r   r   r9   classmethodr@   rJ   propertyr4   r/   rP   rH   rZ   r]   r_   rc   rj   rq   rw   ry   r   r   r   ru   r   r   r   rt   r   r   r   r   r   r   r   r   r   __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                  4    e Zd ZdZedd       ZdddZd	dZy)

Modelspacez: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                     y)z'Name of modelspace is fixed as "Model".Model rM   s    r   r4   zModelspace.namee  s     r!   Nc                :   | j                   j                  t        j                  k  rt        j                  d      |i }| j                         }| j                   j                  j                  |j                  j                  j                  |      }||d<   |S )a  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.)rT   r>   ACAD_GEOGRAPHICDATA)r   
dxfversionr   DXF2010ro   get_extension_dictrB   add_geodata
dictionaryr/   r6   )r:   r>   xdictgeodatas       r   new_geodatazModelspace.new_geodataj  s      88.%%&STTJ'')((""..""&&--! / 
 (/#$r!   c                    	 | j                   j                         }	 |d   S # t        $ r Y yw xY w# t        j                  $ r Y yw xY w)znReturns the :class:`~ezdxf.entities.GeoData` entity associated to
        the modelspace or ``None``.
        Nr   )r   r   AttributeErrorr   DXFKeyError)r:   r   s     r   get_geodatazModelspace.get_geodata  sY    	%%88:E	.//  		    		s   " 1 	..AAr   r   )r   r   )r   zOptional[GeoData])r   r   r   r   r   r4   r   r   r   r!   r   r   r   ]  s%      :r!   r   c                     e Zd ZdZddZddZddZ	 	 d	 	 	 	 	 	 	 	 	 	 	 ddZd ZddZ	ddd	Z
	 	 dd
ZddZddZ	 	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZddZ	 	 	 	 	 	 d 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZddZy)"
Paperspacea  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                :    || j                   j                  _        y)a#  Rename 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.

        NrL   )r:   r4   s     r   renamezPaperspace.rename  s     $( r!   c                n    | D cg c]%  }|j                   s|j                         dk(  s$|' c}S c c}w )z<Get all VIEWPORT entities defined in this paperspace layout.VIEWPORT)is_aliver5   )r:   es     r   	viewportszPaperspace.viewports  s)    La1::!))+2KLLLs   222c                    | j                         D ]E  }|j                  }|j                  d      r|j                  dk(  r|c S |j                  dk(  sC|c S  y)znReturns 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_viewportzPaperspace.main_viewport  sS     ( 	 H,,C{{8$qvv{	  r!   Nc                    |xs i }|\  }}||||d||d}	|	j                  |       t        d| j                  d|	            }
| j                         |
j                  _        |
S )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   )rA   r   rC   get_next_viewport_idr/   r   )r:   r   sizer   r   r   r>   r   r   attribsr   s              r   add_viewportzPaperspace.add_viewport  sq    *  %2
v !2&	
 	z"
DOOJ$HI335r!   c                R    | j                         }|rt        d |D              dz   S y)Nc              3  H   K   | ]  }|j                   j                    y wr   )r/   r   ).0vps     r   	<genexpr>z2Paperspace.get_next_viewport_id.<locals>.<genexpr>  s     5Rrvvyy5s    "r   r$   )r   max)r:   r   s     r   r   zPaperspace.get_next_viewport_id  s*    NN$	595599r!   c                p    | j                         D ]  }| j                  |        | j                          y)z>Delete all existing viewports, and create a new main viewport.N)r   r\   add_new_main_viewport)r:   r   s     r   reset_viewportszPaperspace.reset_viewports  s4     ( 	)Hx(	)""$r!   c                    | j                         }|| j                         }| j                         \  }}||}||}||j                  _        |\  }}||j                  _        ||j                  _        |S )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   r  default_viewport_configr/   r   r   r   )r:   r   r   r   default_centerdefault_sizer   r   s           r   reset_main_viewportzPaperspace.reset_main_viewport  s     %%'113H'+'C'C'E$>#F<D$v"$r!   c                   | j                   j                  }|j                  dk(  rdnd|j                  |j                  z  fd} ||j
                        } ||j                        } ||j                        } ||j                        }| ||j                        z
   ||j                        z
  }| ||j                        z
   ||j                        z
  }|dz  }	|dz  }
|dz  |z
  |dz  |z
  f}||	|
ffS )Nr   r   r   c                    | z  z  S r   r   )rp   scale_factorunit_factors    r   paper_unitsz7Paperspace.default_viewport_config.<locals>.paper_units"  s    ;&55r!   皙?r$   )r.   r/   r   r   r   rf   rg   plot_origin_x_offsetplot_origin_y_offsetleft_marginright_marginbottom_margin
top_margin)r:   r/   r  rf   rg   x_offsety_offsetprintable_widthprintable_heightvp_width	vp_heightr   r  r  s               @@r   r	  z"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                   | j                         \  }}|d   }| j                  ||||d      }t        | j                        dkD  r<| j                  j	                         }||u sJ | j                  j                  d|       d|j                  _        d|j                  _        | j                  |j                  j                         |S )zAdd a new main viewport.r   r   r   r   r   r   r   i  )r	  r   lenr   popinsertr/   r   flagsset_current_viewport_handler6   )r:   r   r   r  r   _vps         r   r  z Paperspace.add_new_main_viewport>  s    335G	))$! * 
 t  !A%##'')C-'''$$Q6 "((():):)A)ABr!   c                :    || j                   j                  _        y r   )r.   r/   viewport_handle)r:   r6   s     r   r%  z&Paperspace.set_current_viewport_handleU  s    .4+r!   c	                f   t        |      dvrt        j                  d      t        |t              rd}	|\  }
}nKt        |t               r&|}	t        j
                  j                  |	d      \  }
}nt        j                  d      |
dk(  rt        j                  d      |dk(  rt        j                  d      |\  }}|\  }}}}|j                         }|j                  d	      rd
}d}d}n!|dk(  rd}d}d}nt        j                  d      | j                  j                  }|j                  d      s|j                  d      |_        | j                  d       d|_        ||_        | d|dd|dd| d|_        ||z  |_        ||z  |_        ||z  |_        ||z  |_        ||z  |_        ||z  |_        |
|_        ||_        ||_        ||_        |\  }}||z  |_        ||z  |_        |	|_        d|z  |_         | jC                          | jE                          | jG                          y)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"r_   F z_(z.2f_x__)N)$rm   r   ro   rX   tuple
STD_SCALESr0   DXFTypeErrorlower
startswithr.   r/   r   get_defaultr_   r   page_setup_nameplot_configuration_file
paper_sizer  r  r  r  rf   rg   r   r   r   plot_rotationr  r  standard_scale_typer  reset_paper_limitsrc   r  )r:   r   marginsunitsoffsetrotationr   r4   devicestandard_scale	scale_numscale_denomrf   rg   
margin_topmargin_rightmargin_bottommargin_leftr   r  r/   r  r  s                          r   
page_setupzPaperspace.page_setupX  s[   J x=,%%&BCCeU#N%*"I{s#"N%*%5%5%9%9.*%U"I{$$K  >%%&CDD!%%&EFF$(!\?F<
L-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                T   | j                   j                  }|j                  dk(  rd}nd}|j                  |z  }|j                  |z  }|j
                  |z  }|j                  |z  }|j                  |z  }|j                  |z  }||z   }	||z   }
|	 |
 f|_	        ||	z
  ||
z
  f|_
        y)zpSet paper limits to default values, all values in paperspace units
        but without plot scale (?).

        r   r   r   N)r.   r/   r   rf   rg   r  r  r  r  rh   ri   )r:   r/   r  rf   rg   r  r  r  r  shift_xshift_ys              r   rB  zPaperspace.reset_paper_limits  s    
 oo!!1$KK oo3''+5oo3))K7++k9++k9 ((*h)
!G+\G-CD
r!   c                ~    t        | j                  j                        t        | j                  j                        fS )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/   rh   ri   rM   s    r   get_paper_limitszPaperspace.get_paper_limits  s)     DHHOO$d488??&;;;r!   c                (   | j                         D ]  }| j                  |        t        |      dvrt        j                  d      t        |t              r$t        j                  j                  |d      \  }}	n|\  }}	|dk(  rt        j                  d      |	dk(  rt        j                  d      |	|z  |j                         }|j                  d      rd}d}
d	}n!|d
k(  rd}d}
d}nt        j                  d      fd} ||d         } ||d         } ||d         } ||d         } ||d         } ||d         }d| j                  j                  d<   ||f| j                  j                  d<   d| j                  j                  d<   ||df| j                  j                  d<   ||z
  |z
  }||z
  |z
  }|dz  }|dz  }|dz  |dz  f}| j                  |||f||d      }d|j                  _        d|j                  _        y )Nr*  zValid rotation values: 0-3)r   r   r   r,  r-  r.  r/  r   r0  r1  r   r   r2  c                    | z  S r   r   )rp   r  s    r   r  z.Paperspace.page_setup_r12.<locals>.paper_units
  s    <''r!   r$   r+  re   $PLIMMIN$PLIMMAX)r   r   r   z$PEXTMINz$PEXTMAXr  r   i  )r   r\   rm   r   ro   rX   r8  r0   r:  r;  r   headerr   r/   r   render_mode)r:   r   rC  rD  rE  rF  r   r   rI  rJ  r   r  r  rK  rL  rM  rN  rf   rg   r  r  r  r  r   r   r  s                            @r   page_setup_r12zPaperspace.page_setup_r12  sQ    ( 	)Hx(	) x=,%%&BCCeS!%*%5%5%9%9%%H"I{%*"I{>%%&CDD!%%&EFF"Y. 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                    | j                   j                  j                  dd      }| j                   j                  j                  dd      }t        |      t        |      fS )z)Returns paper limits in plot paper units.rW  re   rX  )r   rY  r0   r	   )r:   rh   ri   s      r   get_paper_limits_r12zPaperspace.get_paper_limits_r12.  sI    $$Z8$$Z8F|T&\))r!   )r4   rY   r   r   )r   zlist[Viewport])r   zOptional[Viewport])r$   N)r   r
   r   r   r   r
   r   r   r   rm   r   r   r   r   )r   r
   r   r
   r   r   )r   z/tuple[tuple[float, float], tuple[float, float]])r   r   )r6   rY   r   r   )i)     r   r   r   r   r0  re   r   r'   r   zDWG to PDF.pc3)r   r   rC  !tuple[float, float, float, float]rD  rY   rE  r   rF  rm   r   Union[int, tuple[float, float]]r4   rY   rG  rY   r   r   )r   ztuple[Vec2, Vec2])r^  r`  r0  re   r   r'   )r   r   rC  ra  rD  rY   rE  r   rF  r   r   rb  r   r   )r   r   r   r   r   r   r   r   r   r  r  r	  r  r%  rO  rB  rT  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                    d fd j                   J  j                  j                  dk(  rUt        d      }j                  j
                  D ]0  }t        |j                  j                        |k(  s& |       |c S  yt        d      }j                  j
                  D cg c]2  }t        |j                  j                        j                  |      r|4 c}fd} |       }| |d      }|S c c}w )z@Find and link the lost BLOCK_RECORD for the given LAYOUT entity.c           
     "   t         j                  dj                  j                   dt	               dt	        |               | j                  j
                  j                  _        j                  j
                  | j                  _        y )Nzfixing broken links for 'z
' between z and )loggerinfor/   r4   rY   r6   r   r7   )r   r7   s    r   link_layoutz._find_layout_block_record.<locals>.link_layout8  sl    '

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

&"(**"3"3r!   Nr   z*Model_Spacez*Paper_Spacec                    D ]G  }|j                   j                  dd      }j                  j                  |      | u s= |       |c S  y )Nr7   r,   )r/   r0   r   )keyr   layout_handler   rg  paper_space_recordss      r   searchz)_find_layout_block_record.<locals>.searchQ  sT    / 	$L(,,003?M||.#5L)##		$
 r!   )r   r   r   r   )r   r/   r4   r   tablesblock_recordsr;  )r7   ri  r   
search_keyrl  r   rg  rk  s   `    @@@r   r2   r2   5  s    4 **C??zz'!^,JJ44 	$Ll..334;L)##	$   /J  JJ44,**//0;;JG 	 &>Ld|'s   ,7D)r   r   r   rY   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   	getLoggerre  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!   