
    BPc                         d Z ddlZddlmZmZmZ ddlmZ ddlZ G d dej	                  Z
edk    r e
                                             dS dS )a  
An Inkscape effect for adding CAD style dimensions to selected objects
in a drawing.

It uses the selection's bounding box, so if the bounding box has empty
space in the x- or y-direction (such as with some stars) the results
will look strange.  Strokes might also overlap the edge of the
bounding box.

The dimension arrows aren't measured: use the "Visualize Path/Measure
Path" effect to add measurements.

This code contains snippets from existing effects in the Inkscape
extensions library, and marker data from markers.svg.
    N)GroupMarkerPathElement)inkex_gettextc                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )	Dimensionz!Add dimensions as a path modifierc                     |                     dt          dd           |                     dt          dd           |                     ddd	
           d S )Nz	--xoffsetg      I@z(x offset of the vertical dimension arrow)typedefaulthelpz	--yoffsetz*y offset of the horizontal dimension arrowz--type	geometriczBounding box type)r   r   )add_argumentfloat)selfparss     +/usr/share/inkscape/extensions/dimension.pyadd_argumentszDimension.add_arguments.   sz    ;	 	 	
 	
 	
 	=	 	 	
 	
 	
 	(K>QRRRRR    c                 <   t                      }|                    d|           |                    dd           |                    dd           |                    dd           |                    dd           |                    d	|           | j        j                            |           t          d
          }|r|                    dd           n|                    dd           |                    dd           |                    |           dS )z&Create a marker in the defs of the svgidorientautorefXz0.0refYstylezoverflow:visiblezinkscape:stockidz7M 0.0,0.0 L 5.0,-5.0 L -12.5,0.0 L 5.0,5.0 L 0.0,0.0 z )d	transformz(scale(0.8) rotate(180) translate(12.5,0)zscale(0.8) translate(12.5,0)zEfill-rule:evenodd;stroke:#000000;stroke-width:1.0pt;marker-start:noneN)r   setsvgdefsappendr   )r   namerotatemarkerarrows        r   
add_markerzDimension.add_marker=   s   

4

8V$$$

65!!!

65!!!

7.///

%t,,,V$$$WXXX 	CIIk#MNNNNIIk#ABBB		S	
 	
 	
 	er   c                     t                      }|j        |d         | j        j        z  z
  }|j        }||d         | j        j        z  z
  }|                    dd|||fz             |S )zCreate a horzontal liner      r   zM %f %f H %f)r   leftoptionsxoffsetrightyoffsetr   )r   yxlatbboxlinex1x2y1s           r   	horz_linezDimension.horz_lineS   sh    }}Ya4<#777Za4<///nB|3444r   c                     t                      }||d         | j        j        z  z
  }|j        |d         | j        j        z  z
  }|j        }|                    dd|||fz             |S )zCreate a vertical liner   r(   r   zM %f %f V %f)r   r*   r+   topr-   bottomr   )r   xr/   r0   r1   r4   y2s          r   	vert_linezDimension.vert_line\   sh    }}Q$,...XQ$,"666[n2r{2333r   c                 4   | j                             d          }| j        xj        |z  c_        | j        xj        |z  c_        | j         j        s!t          j        t          d                    | j        j	        dk    r| j         j        
                                }n0| j         j                                        
                                }| j                                         }|                     dd           |                     dd           t                      }|                    |           |                    dd	           |                    d
d           |                     |j        ddg|          }|                    dd           |                    dd           |                    dt'          |                     |                    |           |                     |j        ddg|          }|                    dt'          d|z                       |                    |           |                     |j        ddg|          }|                    dt'          d|z                       |                    |           |                     |j        ddg|          }|                    dd           |                    dd           |                    dt'          |                     |                    |           |                     |j        ddg|          }|                    dt'          d|z                       |                    |           |                     |j        ddg|          }|                    dt'          d|z                       |                    |           | j         j                                        D ]}|                    |           |                    |           d S )N1pxzPlease select an objectr   Arrow1LstartF
Arrow1LendTfillnonestrokeblackr   r(   zmarker-startzurl(#Arrow1Lstart)z
marker-endzurl(#Arrow1Lend)zstroke-width   g      ?)r   unittouur*   r+   r-   	selectioninkexAbortExtension_r
   bounding_boxfirstget_current_layerr&   r   r!   r   r5   r7   strr;   r)   r,   r8   values)r   scaler0   layergroupr1   nodes          r   effectzDimension.effecte   s   !!%((%%x! 	E&q)B'C'CDDD<++8%2244DD8%++--::<<D**,,...d+++U		&&!!!		(G$$$~~dhA55!56661222U,,,T~~di!Q66S5[!1!1222T~~dj1a&$77S5[!1!1222T~~di!Q66!56661222U,,,T~~dhA55S5[!1!1222T~~dkAq6488S5[!1!1222TH&--// 	 	DLLUtr   N)	__name__
__module____qualname____doc__r   r&   r5   r;   rS    r   r   r   r   +   sh        ++S S S  ,    6 6 6 6 6r   r   __main__)rW   rG   r   r   r   inkex.localizationr   rI   pathmodifierPathModifierr   rT   runrX   r   r   <module>r^      s   (    , , , , , , , , , , 1 1 1 1 1 1    p p p p p) p p pf zIKKOO r   