
    BPc!                         d Z ddlZddlZddlZddlmZmZ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 )z
This script scatters an object (the pattern) along other paths (skeletons)...
The topmost selected object is the pattern
the other selected ones are the skeletons.

No deformation is applied to the pattern itself.
    N)bezier	TransformBoundingBoxGroupUse)inkex_gettextc                   8     e Zd Z fdZddZd Zd Zd Z xZS )PathScatterc                 \   t          t          |                                            | j                            ddt
          ddd           | j                            ddt
          d	dd
           | j                            ddt          j        ddd           | j                            ddt          ddd           | j                            ddt          j        ddd           | j                            ddt          j        ddd           | j                            ddt
          d d!           | j                            d"d#t          j        d$dd%           | j                            d&d't          d(d)d*           | j                            d+t          d,d-.           d S )/Nz-nz	--noffsetnoffsetg        znormal offset)typedestdefaulthelpz-tz	--toffsettoffsetztangential offsetz-gz--grouppick	grouppickFz6if pattern is a group then randomly pick group membersz-mz
--pickmodepickmoderandz.group pick mode (rand=random seq=sequentially)z-fz--followfollowTz#choose between wave or snake effectz-sz	--stretchstretchz(repeat the path to fit deformer's lengthz-pz--spacespace)r   r   r   z-rz--rotateverticalzreference path is verticalz-cz
--copymodecopymodemovezzHow the pattern is duplicated. Default: 'move',
                                     Options: 'clone', 'duplicate', 'move'z--tabtabz'The selected UI-tab when OK was pressed)r   r   r   )	superr
   __init__
arg_parseradd_argumentfloatinkexBooleanstr)self	__class__s    -/usr/share/inkscape/extensions/pathscatter.pyr   zPathScatter.__init__'   s#   k4  ))+++$$  	% 	
 	
 	
 	$$$ 	% 	
 	
 	
 	$$I 	% 	
 	
 	
 	$$A 	% 	
 	
 	
 	$$6 	% 	
 	
 	
 	$$; 	% 	
 	
 	
 	$$)%gs 	% 	
 	
 	
 	$$- 	% 	
 	
 	
 	$$N 	% 	
 	
 	
 	$$:	 	% 	
 	
 	
 	
 	
    Tc                    |                      |||          \  }}|t          |          dz
  k    r~t          j        ||dz
           ||         d|z             \  }}	||         d         ||dz
           d         z
  |d         z  }
||         d         ||dz
           d         z
  |d         z  }nzt          j        ||         ||dz            |          \  }}	||dz            d         ||         d         z
  ||         z  }
||dz            d         ||         d         z
  ||         z  }|r|
| |g||
|	gg}n
dd|gdd|	gg}t	          |          S )z
        receives a length, and returns the corresponding point and tangent of skelcomp
        if follow is set to false, returns only the translation
           r   )lengthtotimelenr   between_pointr   )r$   sskelcomplengthsisclosedr   itxydxdymats                r&   localTransformAtzPathScatter.localTransformAtt   sg   
   GX661H!!!'Q!a!eLLDAq1+a.8AE?1#55DB1+a.8AE?1#55DBB'Xa!e_aHHDAq1q5/!$x{1~5CB1q5/!$x{1~5CB 	)Q<"b!-CCq!9q!Qi(C~~r'   c                 h   |                                 }t          dd|j        j         gdd|j        j         gg          }| j        j        r4t          |j         |j                   }t          g dg dg          |z  }|                    d| j        j	        g           ||j
        z  |_
        |S )zDTranslates a node to the origin and applies translation if requestedr)   r   )r   r*   r   )r)   r   r   )bounding_boxr   centerr4   r5   optionsr   r   add_translater   	transform)r$   nodebboxr8   s       r&   center_node_at_originz!PathScatter.center_node_at_origin   s      ""!Q/!Q1GHII<  	;w00DZZZ344s:C1dl23444t~-r'   c                    t          | j        j                  dk     r#t          j        t          d                     d S |                     dd          \  }}t                      }|                                	                    |           | j
        j        dk    r)|                    t                                }||_        n|                                }|                     |          }|j        }|| j
        j        z   }|dk     r\t'          |t          j                  r!t          j        t          d                    t          j        t          d                    g }| j
        j        rFt'          |t                    r1|j        }	|D ]&}
|	|
j        z  |
_        |	                    |
           'n|	                    |           |                     ||||           | j
        j        dk    r'|                                                    |           |                                                    |           d S )	N   z+This extension requires two selected paths.Fclone{Gz?z"Please convert texts to path firstzlThe total length of the pattern is too small
Please choose a larger object or set 'Space between copies' > 0r   )r,   svg	selectionr!   errormsg_get_patterns_and_skeletonsr   	getparentappendr=   r   addr   href	duplicaterB   widthr   
isinstanceTextElementAbortExtensionr   r?   _do_transformremove)r$   original_pattern_node	skeletonsg_nodepattern_noderA   rQ   r6   pattern_listr8   childs              r&   effectzPathScatter.effect   s8   tx!""Q&&N1JKKLLLF+/+J+J5RW+X+X(y''))00888< G++!::cee,,L 5L0::<<L )),77
T\''99/1BCC T*1-Q+R+RSSS&V    <! 	.ju&E&E 	.(C% + +"%"7##E****+ ---9e\6BBB< F**!++--445JKKK  ''55555r'   c           
         d}|                                 D ]}|                                 |j                                        }|D ]}|                     |          \  }	}
t          d t          |	d         |	d                   D                       }t          |
          }|| j        j	        z   }| j        j
        r*t          || j        j	        z   |z            }|dk    r||z  }| j        j
        rdn| j        j        dz  |z  }||k    r|                     ||	|
|| j        j                  }| j        j        dk    r%t!          j        dt%          |          dz
            n|t%          |          z  }||                                         }|                    |           ||j        z  |_        ||z  }|dz  }||k    d S )Nr   c                 >    g | ]\  }}t          j        ||          S  )mathisclose).0r2   js      r&   
<listcomp>z-PathScatter._do_transform.<locals>.<listcomp>   s(    SSSDAqT\!Q''SSSr'   r*   rF   r   r)   )valuesapply_transformpathto_superpath	linearizeallzipsumr=   r   r   intr   r9   r   r   randomrandintr,   copyrM   r?   )r$   rX   rQ   r[   rY   counterskelnodecur_skeletoncompr/   r0   skel_closedlengthr6   nr.   local_transformpattern_idxrE   s                      r&   rU   zPathScatter._do_transform   s   !((** "	! "	!H$$&&&#=5577L$ ! !$(NN4$8$8!'!SSCXb\4R4RSSS  WT\//<' *Vdl&88B>??A1uu$\-SAA4<3G$3NQS3S6kk&*&;&;8Wk4<;N' 'O  <0F:: q#l*;*;a*?@@@$s<'8'88   )5::<<EMM%(((&5&GEOGAqLG# 6kk!"	! "	!r'   )T)	__name__
__module____qualname__r   r9   rB   r]   rU   __classcell__)r%   s   @r&   r
   r
   &   s        K
 K
 K
 K
 K
Z   (	 	 	.6 .6 .6`$! $! $! $! $! $! $!r'   r
   __main__)__doc__ro   ra   r!   r   r   r   r   r   inkex.localizationr   rJ   pathmodifierDiffeor
   r{   runr`   r'   r&   <module>r      s   *     < < < < < < < < < < < < < < 1 1 1 1 1 1    A! A! A! A! A!,% A! A! A!H zKMM r'   