
    OgZ                    
   d dl mZ d dlmZmZmZ d dlmZ d dlZd dl	m
Z
 d dlmZ d dlmZmZmZ d dlmZmZmZ d d	lmZ erd d
lmZ d dlmZmZ d dlmZ d dlmZ  ej@                  d      Z! G d de      Z" G d d      Z#y)    )annotations)AnyTYPE_CHECKINGOptional)ProtocolN)MTextLineAlignment)const)DXFAttributeErrorDIMJUSTDIMTAD)Vec3UVecUCS)ARROWS)Drawing)DimStyle	Dimension)BaseDimensionRenderer)xrefezdxfc                      e Zd ZddZy)SupportsOverridec                     y N selfs    d/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/entities/dimstyleoverride.pyoverridezSupportsOverride.override   s        N)returnDimStyleOverride)__name__
__module____qualname__r   r   r    r   r   r      s    r    r   c                  0   e Zd Zd!d"dZed#d       Zed$d       Zd%dZd!d&dZd!d&dZ	d'dZ
d(d	Zd)d
Zd*dZd+dZ	 	 	 	 	 	 d,dZd-dZ	 	 	 	 	 d.	 	 	 	 	 	 	 	 	 	 	 d/dZd0dZd$dZd1d2dZ	 	 	 d3	 	 	 	 	 	 	 d4dZ	 	 	 	 	 	 d5	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d6dZ	 	 	 	 d7	 	 	 	 	 	 	 	 	 	 	 	 	 d8dZ	 	 	 	 	 	 	 d9	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d:dZ	 	 	 	 	 	 d5	 	 	 	 	 	 	 	 	 	 	 d;dZ	 	 	 	 	 d.	 	 	 	 	 	 	 	 	 d<dZd=d>dZd=d>dZd?d@dZdAdZdBdCdZdCdZ d!dDdZ!d=dEd Z"y)Fr"   Nc                    || _         |j                  dd      }| j                  j                  j	                  |      | _        | j                         | _        | j                  |xs i        y )NdimstyleSTANDARD)		dimensionget_dxf_attribdoc	dimstylesgetr(   get_dstyle_dictdimstyle_attribsupdate)r   r*   r   dim_style_names       r   __init__zDimStyleOverride.__init__   sZ    "'66z:N"&(("4"4"8"8"H&*&:&:&< 	HN#r    c                .    | j                   j                  S )zDrawing object (internal API))r*   r,   r   s    r   r,   zDimStyleOverride.doc/   s     ~~!!!r    c                .    | j                   j                  S )zDXF version (internal API))r,   
dxfversionr   s    r   r6   zDimStyleOverride.dxfversion4   s     xx"""r    c                L    | j                   j                  | j                        S )zGet XDATA section ACAD:DSTYLE, to override DIMSTYLE attributes for
        this DIMENSION entity.

        Returns a ``dict`` with DIMSTYLE attribute names as keys.

        (internal API)
        )r*   get_acad_dstyler(   r   s    r   r/   z DimStyleOverride.get_dstyle_dict9   s     ~~--dmm<<r    c                    || j                   v r| j                   |   }|S 	 | j                  j                  ||      }|S # t        $ r |}Y |S w xY w)a  Returns DIMSTYLE `attribute` from override dict
        :attr:`dimstyle_attribs` or base :class:`DimStyle`.

        Returns `default` value for attributes not supported by DXF R12. This
        is a hack to use the same algorithm to render DXF R2000 and DXF R12
        DIMENSION entities. But the DXF R2000 attributes are not stored in the
        DXF R12 file! This method does not catch invalid attribute names!
        Check debug log for ignored DIMSTYLE attributes.

        )r0   r(   r+   r
   )r   	attributedefaultresults       r   r.   zDimStyleOverride.getC   sf     ---**95F 	!55iI  % ! !s   ? AAc                0    | j                  ||      }| |= |S )zReturns DIMSTYLE `attribute` from override dict :attr:`dimstyle_attribs` and
        removes this `attribute` from override dict.
        r.   )r   r:   r;   values       r   popzDimStyleOverride.popW   s      G,Or    c                :    | j                   j                  |       y)z|Update override dict :attr:`dimstyle_attribs`.

        Args:
            attribs: ``dict`` of DIMSTYLE attributes

        N)r0   r1   )r   attribss     r   r1   zDimStyleOverride.update`   s     	$$W-r    c                $    | j                  |      S )z7Returns DIMSTYLE attribute `key`, see also :meth:`get`.r>   r   keys     r   __getitem__zDimStyleOverride.__getitem__i   s    xx}r    c                "    || j                   |<   y)z9Set DIMSTYLE attribute `key` in :attr:`dimstyle_attribs`.Nr0   )r   rE   r?   s      r   __setitem__zDimStyleOverride.__setitem__m   s    %*c"r    c                >    	 | j                   |= y# t        $ r Y yw xY w)zuDeletes DIMSTYLE attribute `key` from :attr:`dimstyle_attribs`,
        ignores :class:`KeyErrors` silently.
        N)r0   KeyErrorrD   s     r   __delitem__zDimStyleOverride.__delitem__q   s'    	%%c* 		s    	c                    | j                   j                  t        j                  k(  sJ dD ];  }| j	                  |d      }|s|j                  t        j                  |             = y N)dimblkdimblk1dimblk2	dimldrblk )r,   r6   r	   DXF12r.   add_block_namer   
block_name)r   registryattrib_name
arrow_names       r   register_resources_r12z'DimStyleOverride.register_resources_r12z   s_     xx""ekk111H 	GK+r2J ''(9(9*(EF	Gr    c                F   | j                   j                  t        j                  k(  sJ |j	                         }dD ]S  }| j                  |d      }|s|j                  t        j                  |            }t        j                  |      ||<   U |j                          y rN   )r,   r6   r	   rT   r   r.   get_block_namer   rV   rY   commit)r   copymappingcopy_overriderX   rY   rV   s          r   map_resources_r12z"DimStyleOverride.map_resources_r12   s    
 xx""ekk111H 	KK+r2J$33F4E4Ej4QR
-3->->z-Jk*		K
 	r    c                N    | j                   j                  | j                         y)zrWrites overridden DIMSTYLE attributes into ACAD:DSTYLE section of
        XDATA of the DIMENSION entity.

        N)r*   set_acad_dstyler0   r   s    r   r]   zDimStyleOverride.commit   s    
 	&&t'<'<=r    c                T    d fd}|t        |       j                  d<   |' |d|       d j                  d<   d j                  d<   |' |d	|       d
 j                  d<   d j                  d<   |' |d|       d
 j                  d<   d j                  d<   |
 |d|       yy)a  Set arrows or user defined blocks and disable oblique stroke as tick.

        Args:
            blk: defines both arrows at once as name str or user defined block
            blk1: defines left arrow as name str or as user defined block
            blk2: defines right arrow as name str or as user defined block
            ldrblk: defines leader arrow as name str or as user defined block
            size: arrow size in drawing units

        c                $    |j                   | <   y r   rH   )dimvarnamer   s     r   	set_arrowz.DimStyleOverride.set_arrows.<locals>.set_arrow   s    ,0D!!&)r    NdimaszrO   r   dimsah        dimtszrP      rQ   rR   )rf   strrg   rn   r!   Nonefloatr0   )r   blkblk1blk2ldrblksizerh   s   `      r   
set_arrowszDimStyleOverride.set_arrows   s    &	1 .3DkD!!(+?h$./D!!(+.1D!!(+i&./D!!(+.1D!!(+i&./D!!(+.1D!!(+k6* r    c                    | j                  dd      }d\  }}|dk(  rXt        | j                  d            r(| j                  dd      }| j                  dd      }||fS | j                  d	d      }|}|}||fS )
zGGet arrow names as strings like 'ARCHTICK' as tuple (dimblk1, dimblk2).rl   r   )rS   rS   rk   rj   rP   rS   rQ   rO   )r.   bool)r   rl   rs   rt   rr   s        r   get_arrow_namesz DimStyleOverride.get_arrow_names   s    (A&
dS=DHHX&'xx	2.xx	2.
 Tz hhx,Tzr    c                J    | j                  dd      }|dk(  rdS t        |      S )Ndimdsepr   ,)r.   chr)r   r|   s     r   get_decimal_separatorz&DimStyleOverride.get_decimal_separator   s'    xx	1-ls4G4r    c                4    t        |      | j                  d<   y)zrUse oblique stroke as tick, disables arrows.

        Args:
            size: arrow size in daring units

        rl   Nrp   )r   rv   s     r   set_tickzDimStyleOverride.set_tick   s     +0+h'r    c                    |r$t         |j                            | j                  d<   |rH|j                         }t        |   | j                  d<   |dk(  r|t	        |      | j                  d<   yyyy)a	  Set measurement text alignment, `halign` defines the horizontal
        alignment, `valign` defines the vertical alignment, `above1` and
        `above2` means above extension line 1 or 2 and aligned with extension
        line.

        Args:
            halign: `left`, `right`, `center`, `above1`, `above2`,
                requires DXF R2000+
            valign: `above`, `center`, `below`
            vshift: vertical text shift, if `valign` is `center`;
                >0 shift upward, <0 shift downwards

        dimjustdimtadcenterNdimtvp)r   lowerr0   r   rq   )r   halignvalignvshifts       r   set_text_alignzDimStyleOverride.set_text_align   sr    & /6v||~/FD!!),\\^F.4VnD!!(+!f&827-%%h/ '9! r    c                   d| j                   d<   d| j                   d<   t        |      | j                   d<   |t        |      | j                   d<   nt        |      | j                   d<   |t        |      | j                   d<   |t        |      | j                   d	<   ||| j                   d
<   ||=d}|du rt        j                  }|du r|t        j
                  z  }|| j                   d<   yy)a  Set tolerance text format, upper and lower value, text height
        factor, number of decimal places or leading and trailing zero
        suppression.

        Args:
            upper: upper tolerance value
            lower: lower tolerance value, if None same as upper
            hfactor: tolerance text height factor in relation to the dimension
                text height
            align: tolerance text alignment enum :class:`ezdxf.enums.MTextLineAlignment`
            dec: Sets the number of decimal places displayed
            leading_zeros: suppress leading zeros for decimal dimensions if ``False``
            trailing_zeros: suppress trailing zeros for decimal dimensions if ``False``

        rm   dimtolr   dimlimdimtpNdimtmdimtfacdimtoljdimtdecFdimtzin)r0   rq   intr	   DIMZIN_SUPPRESSES_LEADING_ZEROS DIMZIN_SUPPRESSES_TRAILING_ZEROS)	r   upperr   hfactoraligndecleading_zerostrailing_zerosr   s	            r   set_tolerancezDimStyleOverride.set_tolerance  s   2 +,h'*+h').ug&-25\D!!'*-25\D!!'*/4W~D!!),/25zD!!),?/2D!!), $(BG%??&5AAA/6D!!), )Cr    c                   d| j                   d<   d| j                   d<   t        |      | j                   d<   t        |      | j                   d<   |t        |      | j                   d<   ||<d}|d	u rt        j                  }|d	u r|t        j                  z  }|| j                   d
<   |t        |      | j                   d<   yy)a  Set limits text format, upper and lower limit values, text
        height factor, number of decimal places or leading and trailing zero
        suppression.

        Args:
            upper: upper limit value added to measurement value
            lower: lower limit value subtracted from measurement value
            hfactor: limit text height factor in relation to the dimension
                text height
            dec: Sets the number of decimal places displayed,
                requires DXF R2000+
            leading_zeros: suppress leading zeros for decimal dimensions if
                ``False``, requires DXF R2000+
            trailing_zeros: suppress trailing zeros for decimal dimensions if
                ``False``, requires DXF R2000+

        rm   r   r   r   r   r   Nr   Fr   r   )r0   rq   r	   r   r   r   )r   r   r   r   r   r   r   r   s           r   
set_limitszDimStyleOverride.set_limits7  s    6 +,h'*+h').ug&).ug&/4W~D!!), $(BG%??&5AAA/6D!!),?/23xD!!), r    c                0   |s|r|dz   |z   | j                   d<   ||| j                   d<   ||| j                   d<   |t        |      | j                   d<   ||=d}|du rt        j                  }|du r|t        j                  z  }|| j                   d	<   yy)
ax  Set dimension text format, like prefix and postfix string, rounding
        rule and number of decimal places.

        Args:
            prefix: dimension text prefix text as string
            postfix: dimension text postfix text as string
            rnd: Rounds all dimensioning distances to the specified value, for
                instance, if DIMRND is set to 0.25, all distances round to the
                nearest 0.25 unit. If you set DIMRND to 1.0, all distances round
                to the nearest integer.
            dec: Sets the number of decimal places displayed for the primary
                units of a dimension. requires DXF R2000+
            sep: "." or "," as decimal separator
            leading_zeros: suppress leading zeros for decimal dimensions if ``False``
            trailing_zeros: suppress trailing zeros for decimal dimensions if ``False``

        <>dimpostNdimrnddimdecr|   r   Fdimzin)r0   ordr	   r   r   )	r   prefixpostfixrndr   sepr   r   r   s	            r   set_text_formatz DimStyleOverride.set_text_formatf  s    6 W/5}w/FD!!),?.1D!!(+?.1D!!(+?/23xD!!), $(BF%>>&%@@@.4D!!(+ )Cr    c                    ||| j                   d<   ||| j                   d<   ||| j                   d<   ||| j                   d<   ||| j                   d<   ||| j                   d<   yy)av  Set dimension line properties.

        Args:
            color: color index
            linetype: linetype as string
            lineweight: line weight as int, 13 = 0.13mm, 200 = 2.00mm
            extension: extension length
            disable1: True to suppress first part of dimension line
            disable2: True to suppress second part of dimension line

        Ndimclrddimltypedimlwddimdledimsd1dimsd2rH   )r   colorlinetype
lineweight	extensiondisable1disable2s          r   set_dimline_formatz#DimStyleOverride.set_dimline_format  s    ( /4D!!),08D!!*-!.8D!!(+ .7D!!(+.6D!!(+.6D!!(+  r    c                    ||| j                   d<   ||| j                   d<   ||| j                   d<   ||| j                   d<   |d| j                   d<   || j                   d<   yy)	a|  Set common extension line attributes.

        Args:
            color: color index
            lineweight: line weight as int, 13 = 0.13mm, 200 = 2.00mm
            extension: extension length above dimension line
            offset: offset from measurement point
            fixed_length: set fixed length extension line, length below the
                dimension line
        Ndimclredimlwedimexedimexorm   dimfxlondimfxlrH   )r   r   r   r   offsetfixed_lengths         r   set_extline_formatz#DimStyleOverride.set_extline_format  s    $ /4D!!),!.8D!!(+ .7D!!(+.4D!!(+#01D!!*-.:D!!(+ $r    c                J    ||| j                   d<   |rd| j                   d<   yy)zSet attributes of the first extension line.

        Args:
            linetype: linetype for the first extension line
            disable: disable first extension line if ``True``

        Ndimltex1rm   dimse1rH   r   r   disables      r   set_extline1zDimStyleOverride.set_extline1  2     08D!!*-./D!!(+ r    c                J    ||| j                   d<   |rd| j                   d<   yy)zSet attributes of the second extension line.

        Args:
            linetype: linetype for the second extension line
            disable: disable the second extension line if ``True``

        Ndimltex2rm   dimse2rH   r   s      r   set_extline2zDimStyleOverride.set_extline2  r   r    c                :    || j                   j                  _        y)zSet dimension text.

        - `text` = " " to suppress dimension text
        - `text` = "" or "<>" to use measured distance as dimension text
        - otherwise display `text` literally

        N)r*   dxftext)r   r   s     r   set_textzDimStyleOverride.set_text  s     #'r    c                @    || j                   d<   || j                   d<   y)zSet relative text movement, implemented as user location override
        without leader.

        Args:
            dh: shift text in text direction
            dv: shift text perpendicular to text direction

        text_shift_htext_shift_vNrH   )r   dhdvs      r   
shift_textzDimStyleOverride.shift_text  s$     13n-02n-r    c                    | j                  |       | j                  j                  dk  }| j                  j                  dv }|s|r#|rdnd| j                  d<   || j                  d<   yy)aZ  Set text location by user, special version for linear dimensions,
        behaves for other dimension types like :meth:`user_location_override`.

        Args:
            location: user defined text location
            leader: create leader from text to dimension line
            relative: `location` is relative to default location.

           )r         rm   dimtmoverelative_user_locationN)user_location_overrider*   dimtyper0   )r   locationleaderrelativelinearcurveds         r   set_locationzDimStyleOverride.set_location  si     	##H-''!+''94V5;D!!*->FD!!":; r    c                    | j                   j                  | j                   j                  dd       t        |      | j                  d<   y)zSet text location by user, `location` is relative to the origin of
        the UCS defined in the :meth:`render` method or WCS if the `ucs`
        argument is ``None``.

        Tr   )staterg   user_locationN)r*   set_flag_stateUSER_LOCATION_OVERRIDEr   r0   )r   r   s     r   r   z'DimStyleOverride.user_location_override  sB     	%%NN11I 	& 	
 26ho.r    c                N    | j                   j                  j                  | |      S )z1Get designated DIMENSION renderer. (internal API))r,   dimension_rendererdispatch)r   ucss     r   get_rendererzDimStyleOverride.get_renderer  s    xx**33D#>>r    c                   | j                  |      }|r| j                  j                  d       n\| j                  j                  j	                  d      }|j
                  | j                  j                  _        |j                  |       |j                          t        | j                        r| j                          |S )aV  Starts the dimension line rendering process and also writes overridden
        dimension style attributes into the DSTYLE XDATA section. The rendering process
        "draws" the graphical representation of the DIMENSION entity as DXF primitives
        (TEXT, LINE, ARC, ...) into an anonymous content BLOCK.

        You can discard the content BLOCK for a friendly CAD applications like BricsCAD,
        because the rendering of the dimension entity is done automatically by BricsCAD
        if the content BLOCK is missing, and the result is in most cases better than the
        rendering done by `ezdxf`.

        AutoCAD does not render DIMENSION entities automatically, therefore I see
        AutoCAD as an unfriendly CAD application.

        Args:
            ucs: user coordinate system
            discard: discard the content BLOCK created by `ezdxf`, this works for
                BricsCAD, AutoCAD refuses to open DXF files containing DIMENSION
                entities without a content BLOCK

        Returns:
            The rendering object of the DIMENSION entity for analytics

        z6DIMENSION entity without geometry BLOCK (discard=True)D)	type_char)r   r,    add_acad_incompatibility_messageblocksnew_anonymous_blockrg   r*   r   geometryrenderfinalizelenr0   r]   )r   r   discardrendererblocks        r   r   zDimStyleOverride.render"  s    2 $$S)HH55H HHOO77#7FE*/**DNN'OOE"t$$%KKMr    r   )r*   r   r   zOptional[dict])r!   r   )r!   rn   )r!   dict)r:   rn   r;   r   r!   r   )rB   r   r!   ro   )rE   rn   r!   r   )rE   rn   r?   r   r!   ro   )rE   rn   r!   ro   )rW   zxref.Registryr!   ro   )r^   r   r_   zxref.ResourceMapperr!   ro   )r!   ro   )NNNNN)rr   Optional[str]rs   r   rt   r   ru   r   rv   Optional[float]r!   ro   )r!   ztuple[str, str])rm   )rv   rq   r!   ro   )NNN)r   r   r   r   r   r  r!   ro   )NNNNNN)r   rq   r   r  r   r  r   zOptional[MTextLineAlignment]r   Optional[int]r   Optional[bool]r   r  r!   ro   )NNNN)r   rq   r   rq   r   r  r   r  r   r  r   r  r!   ro   )rS   rS   NNNNN)r   rn   r   rn   r   r  r   r  r   r   r   r  r   r  r!   ro   )r   r  r   r   r   r  r   r  r   r  r   r  )
r   r  r   r  r   r  r   r  r   r  )NF)r   r   )r   )r   rn   r!   ro   )r   rq   r   rq   r!   ro   )FF)r   r   r!   ro   )r   Optional[UCS])r   r  r!   r   )#r#   r$   r%   r3   propertyr,   r6   r/   r.   r@   r1   rF   rI   rL   rZ   ra   r]   rw   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r"   r"      s   $$ " " # #=(.+
G$/B	4> """ $ $%+%+ %+ 	%+
 %+ %+ 
%+N56 !% $"&	@@ @  	@
 
@> "&#'.2!(,)-/7/7 /7 !	/7
 ,/7 /7 &/7 '/7 
/7j $(!(,)--8-8 -8 !	-8
 -8 &-8 '-8 
-8b #!!(,)-+5+5 +5 	+5
 +5 +5 &+5 '+5 
+5^  $"&$(%)#'#'77  7 "	7
 #7 !7 !7F  $$(%)"&(,;; "; #	;
  ; &;<00'
3G"	@?%r    r"   )$
__future__r   typingr   r   r   typing_extensionsr   loggingezdxf.enumsr   ezdxf.lldxfr	   ezdxf.lldxf.constr
   r   r   
ezdxf.mathr   r   r   ezdxf.render.arrowsr   ezdxf.documentr   ezdxf.entitiesr   r   ezdxf.render.dim_baser   r   r   	getLoggerloggerr   r"   r   r    r   <module>r     sd    # / / &  *  @ @ & & &&2;			7	#x 
k kr    