
    Og&^                       d dl mZ d dlmZmZmZmZ d dlZd dlm	Z	m
Z
mZmZmZ d dlmZmZ d dlmZ ddlmZmZmZmZmZ erd d	lmZ d d
lmZ  G d de      Zej<                  ej>                  ej@                  ejB                  ejD                  ejF                  ejH                  ejJ                  ejL                  ejN                  ejP                  ejR                  hZ*	 d	 	 	 	 	 ddZ+	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ,y)    )annotations)TYPE_CHECKINGIterablecastOptionalN)Vec3Vec2UVecConstructionRayUCS)ARROWSconnection_point)DimStyleOverride   )BaseDimensionRendererLengthMeasurementMeasurementcompile_mtextorder_leader_points)	Dimension)GenericLayoutTypec                       e Zd ZdZ	 	 d	 	 	 	 	 d fdZddZd fdZddZddZddZ	d Z
	 	 	 	 	 	 	 	 dd	Zdd
Z	 d	 	 	 	 	 ddZddZ xZS )LinearDimensiona  Linear dimension line renderer, used for horizontal, vertical, rotated
    and aligned DIMENSION entities.

    Args:
        dimension: DXF entity DIMENSION
        ucs: user defined coordinate system
        override: dimension style override management object

    c                   t         |   |||       | j                  }|j                  dk(  rd|_        | j                  j                  dd      | _        | j                  j                  dd      | _        t        j                  | j                        | _
        | j                  | j                  z   | _        t        j                  | j                        | _        | j                  |_        |j                  dv r| j                  |_        t        | j                  j                   j"                        | _        t        | j                  j                   j&                        | _        t+        | j$                  | j                        }t+        | j(                  | j                        }t+        | j                  j                   j,                  | j                        }|j/                  |      | _        |j/                  |      | _        | j0                  j5                  | j2                        | _        | j0                  | j2                  k(  r%t        j8                  | j                        | _        n,| j2                  | j0                  z
  j=                         | _        t?        | j0                        | j                  j                   _        | j2                  | j0                  z
  j@                  }|jC                  |       | jD                  jG                  dd	      | _$        | jD                  jG                  d
d       | _%        d| _&        d| jN                  jP                  z  |jR                  z   | _*        | jT                  |kD  | _+        |jX                  r| j[                         | _&        | j\                  j^                  r/| j\                  ja                  | j                  jb                         | jH                  rd|_2        |jf                  dk(  r?ti        |jd                        dk  r'| jL                  d| jN                  jP                  z  z   }	n| jL                  }	|	|kD  |_5        |jl                  s|jj                  |_7        n"|jj                  r|j                  dk  rd|_        | jH                  r|jj                  r| jJ                  r|jp                  |jR                  z   }
| jJ                  dk(  r,|
|_9        |jt                  dk(  rQ|xjr                  |
z  c_9        n;| jJ                  dk(  r,|
 |_9        |jt                  dk(  r|xjr                  |
z  c_9        | jw                         |_<        |j                  }|jz                  |jz                  }n5|jn                  r|j|                  rd}n|j~                  r|j                  rd}||_        | j                         }| j                  j                  |       |j                  rY|j                  ^}}}t        | j6                  ||      \  | _G        | _H        | j                  | j                  j                   _I        y |jx                  | j                  j                   _I        y y )Nr      oblique_angleZ   angle      )r   multi_point_modeFmove_wide_text        gffffff?r    r   )Jsuper__init__measurementtext_movement_rule	dimensionget_dxf_attribr   dim_line_anglemathradiansdim_line_angle_radext_line_angleext_line_angle_radtext_rotationtext_halignr	   dxf	defpoint2ext1_line_start	defpoint3ext2_line_startr   defpoint	intersectdim_line_startdim_line_endlerpdim_line_center
from_angledim_line_vec	normalizer   	magnitudeupdate	dim_stylepopr"   r#   _total_text_widtharrows
arrow_sizetext_gaprequired_arrows_spacearrows_outsidetexttotal_text_widthtol
has_limitsupdate_limitsvaluetext_vertical_positiontext_valignabsis_wide_textforce_text_insidetext_is_outsidetext_heighttext_shift_vvertical_placementget_text_locationtext_locationuser_text_rotationtext_outside_horizontaltext_is_insidetext_inside_horizontalinit_text_boxgeometryset_text_box
has_leadercornersr   leader1leader2text_midpoint)selfr*   ucsoverrider(   ext1_rayext2_raydim_line_rayraw_measurementrequired_spaceshift_valuerotationtext_boxp1p2_	__class__s                   \/var/www/html/public_html/myphp/venv/lib/python3.12/site-packages/ezdxf/render/dim_linear.pyr'   zLinearDimension.__init__"   sp    	C2&&))Q. ./K*$(NN$A$AR%
 &*^^%B%B7A%N)-d6I6I)J%)%8%84;M;M%M)-d6I6I)J %)$7$7!""f,(,(;(;K%#DNN$6$6$@$@A#DNN$6$6$@$@A"  (?(?
 #  (?(?
 'NN''t/F/F
 %1$:$:8$D"."8"8"B%)%8%8%=%=d>O>O%P$"3"33 $0G0G HD !!D$7$77ik 
 '+4+>+>&?#,,t/B/BBMM?+ !% 2 23Eu M
 /3nn.@.@d/

 )* &&&)=)== 	" %)$>$>$P %)%:%:%<D"xx"" &&t'7'7'='=>$$ 692 ''1,::;cA **Q1G1G-GG  "&!7!7'5'GK$00.9.F.F+))k.E.E.I*+'
 %%,,'')558L8LL&&!+/:K,#66"< $00K?0((A-0;|K,#66!; $00K?0 )-(>(>(@K% *77H--9&99++77**66(0K%))+HMM&&x0%%%--
B-@(("b.*dl 48<<""0 4?3L3L""0k     c                X    t        | j                  | j                  | j                        S N)r   rD   default_color	dim_scale)ri   colorscales      rx   init_measurementz LinearDimension.init_measurement   s$     NND..
 	
ry   c                   t         |   |       | j                  }| j                  }|j                  s\|j
                  dk(  }| j                  | j                  | j                  |      \  }}| j                  |||j                  d             |j                  s\|j
                  dk(  }| j                  | j                  | j                  |      \  }}| j                  |||j                  d             | j                         \  }}	| j                  ||	       |j                   r| j"                  j$                  rt'        || j(                        }
n|j                   }
| j+                  |
|j,                  |j.                         |j0                  r1| j3                  | j4                  | j6                  | j8                         | j"                  j;                  | j                  | j                  | j                  g       y)zMain method to create dimension geometry of basic DXF entities in the
        associated BLOCK layout.

        Args:
            block: target BLOCK for rendering

        r    r   
dxfattribsr!   r   N)r&   renderextension_linesr(   	suppress1r3   extension_line_pointsr6   r;   add_liner   	suppress2r8   r<   
add_arrowsadd_dimension_linerL   rb   supports_dxf_r2000r   rN   add_measurement_textr\   r2   rd   
add_leaderr>   rf   rg   add_defpoints)ri   block	ext_linesr(   above_ext_line1startendabove_ext_line2r;   r<   rL   rw   s              rx   r   zLinearDimension.render   s    	u ((	&&"")55:O33$$d&9&9?JE3 MM%1E1Ea1HMI "")55:O33$$d&7&7JE3 MM%1E1Ea1HMI (,'8$ 	= }}//$[$((;"''%%k//1J1J %%(($,,
 	##  $"6"68L8LM	
ry   c                H   | j                   }|j                  r=| j                         }|j                  ||j                        }| j                  |       |j                  0|j                  }|j                  r| j                  |z   }d|_	        |S | j                         }|S )z_Get text midpoint in UCS from user defined location or default text
        location.

        T)
r(   has_relative_text_movementdefault_text_locationapply_text_shiftr2   location_overrideuser_locationrelative_user_locationr>   rW   )ri   r(   locations      rx   r[   z!LinearDimension.get_text_location  s     &&11113H"33+33H ""8,$$0"00H11//(:*.K'  113Hry   c                p   | j                   }| j                  }| j                  }|j                  }| j                  }|dv r|j
                  |j                  dz  z   }| j                  |z  }|dk(  r|n||z
  }|j                  | j                  dz  z   }	|t        j                  | j                        j                  |	      z  }|S |j                  rd}|dk(  r| j                  }n]| j                  dz  | j                   j"                  z   |j
                  z   }|dk(  r|| j                  |z  z   }n|| j                  |z  z
  }|j                  r*|j                  |j
                  z   |j                  dz  z   }	n|j%                         }	|| j                  j'                         j                  |	      z  }|S )zCalculate default text location in UCS based on `self.text_halign`,
        `self.text_valign` and `self.text_outside`

        r          @r    r   r   )r;   r<   r(   r3   r   rI   rX   r@   extension_aboverF   r	   from_deg_angler0   rA   rW   r>   rG   rH   text_vertical_distance
orthogonal)
ri   r   r   r(   halignr   hdisthvecr   vdists
             rx   r   z%LinearDimension.default_text_location  s   
 ##&&((((	V((;+B+BS+HHE$$u,D!'1#=H--0F0F0LLE++D,?,?@JJ HD ; **{// **S0kk,,-!**+  aK$(9(9E(ABH"d&7&7%&?@H**--!**+!--34  $::<))446@@GGHry   c                N   | j                   }|j                         }| j                  }| j                  }| j                  }|j
                   }|j                   }|j                  dkD  r~|r;| j                  t        j                  || j                  |j                  dz  |       |r;| j                  t        j                  || j                  |j                  dz  |       ||fS |j                  }| j                  dz   }	| j                  }
|r|
|	}
}	|r | j                  |j                  |||	|       |r | j                  |j                  |||
|       |s8|rt        |j                  |||	      }|rt        |j                  |||
      }||fS | j!                          ||fS )zg
        Add arrows or ticks to dimension.

        Returns: dimension line connection points

        r$   r   )insertrr   r   r   g     f@)r   r   rr   r   )rG   r   r;   r<   rK   r   r   	tick_sizeadd_blockrefr   obliquer,   rH   arrow1_namearrow2_namer   add_arrow_extension_lines)ri   rG   attribsr   r   outsidearrow1arrow2r   start_angle	end_angles              rx   r   zLinearDimension.add_arrowsQ  s    ##%##%%%%%%%%c!!!NN !00 **S0& "  !!NN!00 **S0& " \ czM %%E--5K++I)2KY!!&& (& "  !!&&&& "   ,**E5+E ***C	C cz ..0czry   c                   dd}| j                   j                         }| j                  }| j                  }| j                  }|j
                  }|j                  sI ||j                        r7| j                  || j                  |z  z
  || j                  d|z  z  z
  |       |j                  sK ||j                        r8| j                  || j                  |z  z   || j                  d|z  z  z   |       yyy)z{Add extension lines to arrows placed outside of dimension extension
        lines. Called by `self.add_arrows()`.

        c                F    | d uxr | t         v xr | t         j                  vS r{   )r   ORIGIN_ZERO)names    rx   has_arrow_extensionzFLinearDimension.add_arrow_extension_lines.<locals>.has_arrow_extension  s.    T! 5V^5!3!33ry   r   r   N)r   strreturnbool)dimension_liner   rG   r;   r<   rH   r   r   r   r@   r   r   )ri   r   r   rG   r   r   rH   s          rx   r   z)LinearDimension.add_arrow_extension_lines  s    	 %%002##&&
$78J8J$KMM))J66))Q^<<"   $78J8J$KMMd''*44d''1z>::"   %Lry   c                <    | j                  |||t                      y)zAdd measurement text to dimension BLOCK.

        Args:
            dim_text: dimension text
            pos: text location
            rotation: text rotation in degrees

        N)add_textdict)ri   dim_textposrr   s       rx   r   z$LinearDimension.add_measurement_text  s     	hXtv6ry   c                :   | j                   }| j                  }| j                  |j                  z  }|j                  }|st        j                  |j                        r||z
  }|st        j                  |j                        r||z   }|j                         }|j                  s|j                  rU|j                  |      }|j                  s| j                  |||d       |j                  s| j                  |||d       yy| j                  |||d       y)a9  Add dimension line to dimension BLOCK, adds extension DIMDLE if
        required, and uses DIMSD1 or DIMSD2 to suppress first or second part of
        dimension line. Removes line parts hidden by dimension text.

        Args:
            start: dimension line start
            end: dimension line end

        T)r   remove_hidden_linesN)r   rG   r@   	extension	has_ticksr   has_extension_liner   r   r   r   r   r=   r   )	ri   r   r   dim_linerG   r   ticksr   centers	            rx   r   z"LinearDimension.add_dimension_line  s    &&%%(:(::	  F--f.@.@AI%EF--f.@.@A	/C%%'!3!3 ZZ_F%%6g4   %%CG   &
 MMswD  ry   c                v   ||k(  r t        j                  | j                        }n||z
  j                         }| j                  j
                  r||| j                  j                  z  z
  }n||| j                  j                  z  z   }| j                  j                  }|r|| j                  z  }|||z  z   }||fS )a  Adjust start and end point of extension line by dimension variables
        DIMEXE, DIMEXO, DIMEXFIX, DIMEXLEN.

        Args:
            start: start point of extension line (measurement point)
            end: end point at dimension line
            text_above_extline: True if text is above and aligned with extension line

        Returns: adjusted start and end point

        )
r	   r   r0   rA   r   has_fixed_lengthlength_belowoffsetr   rF   )ri   r   r   text_above_extline	directionr   s         rx   r   z%LinearDimension.extension_line_points  s     C<++D,?,?@Iu//1I009t';';'H'HHIEI(<(<(C(CCCE((88	///II	))czry   c                d     fd} j                   j                  } |d|j                          |d|j                          |d|j                          |d|j                         |j	                   j
                  j                  j                         j
                  j                  _        y)zTransforms dimension definition points into WCS or if required into
        OCS.

        Can not be called in __init__(), because inherited classes may be need
        unmodified values.

        c                    j                   j                  |       }j                   j                  |  ||             y r{   )r*   r+   set_dxf_attrib)attrfuncpointri   s      rx   from_ucsz6LinearDimension.transform_ucs_to_wcs.<locals>.from_ucs  s/    NN11$7ENN))$U<ry   r9   r5   r7   rh   N)rb   rj   to_wcsto_ocsto_ocs_angle_degr*   r4   r   )ri   r   rj   s   `  rx   transform_ucs_to_wcsz$LinearDimension.transform_ucs_to_wcs
  s    	= mmSZZ(cjj)cjj)#**-#&#7#7NN$$$
 ry   )NN)r*   r   rj   Optional[UCS]rk   zOptional[DimStyleOverride])r~   intr   floatr   r   )r   r   r   None)r   r	   )r   tuple[Vec2, Vec2])r   r   r   r	   rr   r   r   r   )r   r	   r   r	   r   r   )F)r   r	   r   r	   r   r   )r   r   )__name__
__module____qualname____doc__r'   r   r   r[   r   r   r   r   r   r   r   __classcell__)rw   s   @rx   r   r      s     "/3	bMbM bM -	bMH

5
n24lGRB77"&7277	7$N :? $	8
ry   r   c                    t        j                  |      }| D cg c]  }|j                  t        |            |f  }}t        |      D cg c]  \  }}|	 c}}S c c}w c c}}w r{   )r	   r   projectsorted)pointsr   r   pprojected_vectors
projections         rx   sort_projected_pointsr   1  s`     ##E*IBHIQ)++DG4a8II#)*;#<=-*aA== J=s   #AA"c
           
        dd}
t        ||      }t        |      }|xs i }d|d<   d|d<   d|d<   d}d}d}t        |d	d
 |dd	       D ]  \  }}t        |      }||d<   |r|s
d|d<   ||d<   | j	                  t        |      t        |      t        |      ||||      }|r |
|      }t        t        |j                  ||	            }|j                  j                  r|dk(  rd}nd}nd}d} y	)a  Creates multiple DIMENSION entities for each point pair in `points`.
    Measurement points will be sorted by appearance on the dimension line
    vector.

    Args:
        layout: target layout (model space, paper space or block)
        base: base point, any point on the dimension line vector will do
        points: iterable of measurement points
        angle: dimension line rotation in degrees (0=horizontal, 90=vertical)
        ucs: user defined coordinate system
        avoid_double_rendering: removes first extension line and arrow of
            following DIMENSION entity
        dimstyle: dimension style name
        override: dictionary of overridden dimension style attributes
        dxfattribs: DXF attributes for DIMENSION entities
        discard: discard rendering result for friendly CAD applications like
            BricsCAD to get a native and likely better rendering result.
            (does not work with AutoCAD)

    c                @    | j                         \  }}||t        v ryy)NTF)get_arrow_namesCAN_SUPPRESS_ARROW1)dimstyle_overridearrow_name1arrow_name2s      rx   suppress_arrow1z5multi_point_linear_dimension.<locals>.suppress_arrow1Z  s)    #4#D#D#F [[4G%Gry   r   dimtixr   dimtvpTr"   FNr%   r#   dimse1r   )r   dimstylerk   r   )discardr   )r   r   )r   r	   zipr   add_linear_dimr   r   r   r   r(   rU   )layoutbaser   r   rj   avoid_double_renderingr   rk   r   r   r   r#   _suppress_arrow1	first_runrt   ru   	_overridestylerenderers                      rx   multi_point_linear_dimensionr  9  s7   B #651F:D~2HHXHX#'H  NIfSbk6!":. BN	&4	"#!)"#Ih+;I'(%%JHH! & 
 .u5c7)KL,,"!"!"N	9ry   )r   )r   Iterable[UVec]r   r   r   z
list[Vec2])r   NTEZDXFNNF)r   r   r   r
   r   r  r   r   rj   r   r   r   r   r   rk   zOptional[dict]r   r   )-
__future__r   typingr   r   r   r   r-   
ezdxf.mathr   r	   r
   r   r   ezdxf.render.arrowsr   r   ezdxf.entities.dimstyleoverrider   dim_baser   r   r   r   r   ezdxf.entitiesr   ezdxf.eztypesr   r   dot	dot_small	dot_blankorigin_indicatororigin_indicator_2dot_smallblanknoner   
box_filledboxintegralarchitectural_tickr   r   r   ry   rx   <module>r     sN   # : :  = = 8 <  (/G
+ G
V JJ





KK
NN

JJ
OO
 " ,->>#(>> #'#PP
P P 	P
 
P !P P P 
Pry   