Ë
    £èhÌ~  ã                  ó"  — 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      ú4lib/python3.12/site-packages/ezdxf/layouts/layout.pyÚget_block_entity_spacer       s   € Ø—<‘<Ð 3Ñ4€LØ×$Ñ$Ð$ó    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
  ø€ Ø ˆŒØ—‘—‘Ð 5°sÓ;ˆð	ØŸ<™<¨Ñ/ˆLð ×ÑÓ! ^Ò3Ü×)Ñ)Ø)¨&¨°ÀÇ
Á
ÇÁÐ?Pð Q,Ø,8×,@Ñ,@Ó,BÐ+CðEóð ð
 #)§*¡*×"3Ñ"3ˆ×ÑÔÜ‰Ñ˜Õ&øô ò 	Ü4°VÓ<ˆLØÐ#Ü×-Ñ-Ø-¨f¨X°]À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   € ð  %(§J¡J§N¡N°:Ó$>ˆØÒ% 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!   € ñ �f˜cÓ"ˆØ×"Ñ"Ô$Øˆ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 )záReturns 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˜   sb   € ð —_‘_ˆ
Ø×,Ò,‘Q°!ˆ
ÛˆFØ�z‰z×Ñ :Ò-Ø#-�—
‘
Ô Ø�z‰z×$Ñ$¨
Ó2Ø(2�—
‘
Õ%ñ	 r!   c                ó†   — t        |t        «      r| j                  |   }|j                  j                  | j
                  k(  S )z—Returns ``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   € ô �fœcÔ"Ø—]‘] 6Ñ*ˆFØ�z‰z×Ñ 4§?¡?Ñ2Ð2r!   c                ó€   •— | j                   j                  j                  | j                  «       t        ‰| �  «        y)z‚Delete 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!   € ð �o‰o×!Ñ!ˆØˆŒ
Øˆ�
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   € ð  �o‰o×!Ñ!ˆØˆ>ØˆFØˆ>Ø—o‘o s×'7Ñ'7Ð8ˆFàˆŒ
Øˆ�
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ÕØ!&ˆD�H‰HÕä×%Ñ%Ð&KÓLÐLr!   c                ó~   — || j                   j                  _        | j                  d«       | j	                  |«       y)z´Set 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)zºSet 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Ø�o‰o×!Ñ!ˆØˆÔØˆÔØˆÔØˆÔØ×Ñ˜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   € Ø—‘×*Ñ*ˆØ—H‘H×,Ñ,ˆ	ØˆÙØ Ñ%ˆEØ�8‰8×$Ñ$¨Ò)Øˆ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Ñ1°5Õ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Ñ3°UÕ;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Ñ2°EÕ: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Ñ5°uÕ=r!   c                ó<   — | j                  | j                  |«       y r   )r‘   Ú
MODEL_TYPEr“   s     r   Ú
model_typezLayout.model_typeJ  s   € Ø×Ñ˜DŸO™O¨UÕ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   € Ø�‰×&Ñ& t°5Ð?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Ž   € ð  �8‰8×Ñ¤§¡Ò.Ü×%Ñ%Ð&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-   € áÓL™4�a 1§:£:°!·)±)³+ÀÓ2K’˜4Ñ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·  sN   € ð Ÿ™Ö(ˆHØ—,‘,ˆCØ�{‰{˜8Ô$¨¯©°qªØ’Ø�v‰v˜‹{Ø’ð )ð 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Ô"Ü˜
 D§O¡O°JÀÓ$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   è ø€ Ð5©9 R�r—v‘v—y•y©9ùs   ‚ "r   r$   )rì   Úmax)r:   rì   s     r   rû   zPaperspace.get_next_viewport_idì  s*   € Ø—N‘NÓ$ˆ	ÙÜÑ5©9Ó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ò  s/   € ð Ÿ™Ö(ˆ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Ó3ˆHØ'+×'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$  ù€ ð �o‰o×!Ñ!ˆØ×Ñ 1Ò$Ø‰KàˆKð ×,Ñ,¨s×/BÑ/BÑBˆõ	6ñ " #§/¡/Ó2ˆÙ" 3×#3Ñ#3Ó4ˆá˜s×7Ñ7Ó8ˆÙ˜s×7Ñ7Ó8ˆð ™+ c§o¡oÓ6Ñ6¹ÀS×EUÑEUÓ9VÑVð 	ð ™; s×'8Ñ'8Ó9Ñ9¹KÈÏÉÓ<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ä�eœUÔ#Øˆ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ð �o‰o×!Ñ!ˆØ�{‰{Ð.Ô/Ø$'§O¡OÐ4GÓ$HˆCÔ!Ø×Ñ Ô&Ø ˆÔØ&,ˆÔ#Ø ˜6  K°Ð#4°C¸ÀSÐ7IÈÈ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Å   € ð
 �o‰o×!Ñ!ˆØ×Ñ 1Ò$Ø‰KàˆKð —o‘o¨Ñ3ˆØ×'Ñ'¨+Ñ5ˆØ—o‘o¨Ñ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)   € ô �D—H‘H—O‘OÓ$¤d¨4¯8©8¯?©?Ó&;Ð;Ð;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à  sL  ø€ ð Ÿ™Ö(ˆHØ×Ñ˜xÕ(ð )ô ˆx‹= Ñ,Ü×%Ñ%Ð&BÓCÐCä�eœSÔ!Ü%*×%5Ñ%5×%9Ñ%9¸%ÀÓ%HÑ"ˆI‘{à%*Ñ"ˆI�{à˜Š>Ü×%Ñ%Ð&CÓDÐDØ˜!ÒÜ×%Ñ%Ð&EÓFÐFà" YÑ.ˆð —‘“ˆØ×Ñ˜FÔ#ØˆEØ ÐØ‰KØ�dŠ]ØˆEØ ÐØ‰Kä×%Ñ%Ð&HÓIÐIô	(ñ ! ¨¡Ó,ˆ
Ù" 7¨1¡:Ó.ˆÙ# G¨A¡JÓ/ˆÙ! '¨!¡*Ó-ˆÙ! $ q¡'Ó*ˆÙ" 4¨¡7Ó+ˆØ&,ˆ�‰�‰˜
Ñ#Ø'2°LÐ&Aˆ�‰�‰˜
Ñ#Ø&/ˆ�‰�‰˜
Ñ#Ø'2°LÀ!Ð&Dˆ�‰�‰˜
Ñ#ð &¨Ñ3°lÑ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¸
Ä3ÀvÃ;À-ÈuÔUXÐYeÓUfÐTgÐ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  sO   ø€ Û/ˆLØ(×,Ñ,×0Ñ0°¸3Ó?ˆMØ�|‰|×Ñ Ó.°#Ò5Ù˜LÔ)Ø#Ò#ð	 0ð
 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Øˆ?Ðˆ?Ø‡z�z‡�˜'Ò!Ü˜^Ó,ˆØŸJ™J×4Ô4ˆLÜ˜l×.Ñ.×3Ñ3Ó4¸Ó;Ù˜LÔ)Ø#Ò#ð 5ð ô   Ó/€Jð  ŸJ™J×4Ò4óá4ˆLÜ˜,×*Ñ*×/Ñ/Ó0×;Ñ;¸JÔGò 	Ø4ñÐöñ ˜&“>€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!   