
    BPcb!                         d Z ddlZddlZddlZddlmZ ddl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@  
This script deforms an object (the pattern) along other paths (skeletons)...
The first selected object is the pattern
the last selected ones are the skeletons.

Imagine a straight horizontal line L in the middle of the bounding box of the pattern.
Consider the normal bundle of L: the collection of all the vertical lines meeting L.
Consider this as the initial state of the plane; in particular, think of the pattern
as painted on these lines.

Now move and bend L to make it fit a skeleton, and see what happens to the normals:
they move and rotate, deforming the pattern.
    N)tpoint)CubicSuperPath)inkex_gettextc                   ,    e Zd ZdZd ZddZd Zd ZdS )	PathAlongPathz!Deform a path along a second pathc                    |                     ddt          dd           |                     ddt          dd           |                     d	d
t          d           |                     dddd           |                     ddt          d           |                     ddt          j        dd           |                     ddt          j        dd           |                     dd           d S )Nz-nz	--noffsetg        znormal offset)typedefaulthelpz-tz	--toffsetztangential offsetz-kz--kind )r	   r
   z-cz
--copymodeSinglez(repeat the path to fit deformer's length)r
   r   z-pz--spacez-vz
--verticalFzreference path is verticalz-dz--duplicateTz$duplicate pattern before deformationz--tabz'The selected UI-tab when OK was pressed)r   )add_argumentfloatstrinkexBoolean)selfparss     //usr/share/inkscape/extensions/pathalongpath.pyadd_argumentszPathAlongPath.add_arguments0   s<   +E3_ 	 	
 	
 	
 	+E3=P 	 	
 	
 	
 	$sB???;	 	 	
 	
 	
 	$	sCCC- 	 	
 	
 	
 	7 	 	
 	
 	
 	'(QRRRRR     c                 .   |d         |d         d         z
  }|                      |||          \  }}|t          |          dz
  k    ryt          ||dz
           ||         d|z             \  }	}
||         d         ||dz
           d         z
  |d         z  }||         d         ||dz
           d         z
  |d         z  }nut          ||         ||dz            |          \  }	}
||dz            d         ||         d         z
  ||         z  }||dz            d         ||         d         z
  ||         z  }d}|d         |d         d         z
  }| j        j        r|	||z  z   |d<   |
|z   ||z  z   |d<   n"|	||z  z   ||z  z
  |d<   |
||z  z   ||z  z   |d<   |D ]{}|d         |d         d         z
  |z
  }|d         |d         d         z
  }| j        j        r|	||z  z   |d<   |
|z   ||z  z   |d<   Y|	||z  z   ||z  z
  |d<   |
||z  z   ||z  z   |d<   |dS )z
        The kernel of this stuff:
        bpt is a base point and for v in vectors, v'=v-p is a tangent vector at bpt.
        r      N)lengthtotimelenr   optionswave)r   bptskelcomplengthsisclosedvectssitxydxdyvxvyvs                   r   apply_diffeomorphismz"PathAlongPath.apply_diffeomorphismO   sn   
 FXa[^#  GX661H!!!(1q5/8A;A>>DAq1+a.8AE?1#55DB1+a.8AE?1#55DBB(1+xA::DAq1q5/!$x{1~5CB1q5/!$x{1~5CBVhqk!n$< 	+b[CFVb2g%CFFb[27*CFb[27*CF 	- 	-A1A&*B1A&B|  -27{!2vR'!27{R"W,!27{R"W,!	- 	-r   c                    t          | j        j                  dk     r!t          j        t          d                    | j        j        dk    | j        _        | j        j        dk    rd| j        _	        d| j        _
        nz| j        j        dk    rd| j        _	        d| j        _
        nQ| j        j        dk    rd| j        _	        d| j        _
        n(| j        j        d	k    rd| j        _	        d| j        _
        |                     d| j        j                  \  }}d
 |                                D             }d |v r!t          j        t          d                    t          |d           }| j        j        r!t          j        |j         |j                   }|j        }|| j        j        z   }|dk     r!t          j        t          d                    |                                D ]d}t+          |t          j                  rH|                                 |                     ||j                                        ||          |_        ed S )N   z+This extension requires two selected paths.Ribbonr   FRepeatedTzSingle, stretchedzRepeated, stretchedc                 6    g | ]}|                                 S r   )bounding_box).0patterns     r   
<listcomp>z(PathAlongPath.effect.<locals>.<listcomp>   s$    JJJW'&&((JJJr   z"Please convert texts to path firstg{Gz?zlThe total length of the pattern is too small
Please choose a larger object or set 'Space between copies' > 0)r   r   idsr   AbortExtension_kindr   copymoderepeatstretchget_patterns_and_skeletons	duplicatevaluessumverticalBoundingBoxr)   r(   widthspace
isinstancePathElementapply_transform_do_transformpathto_superpath)r   patternsskelsbboxesbboxrF   delta_xr7   s           r   effectzPathAlongPath.effectr   s9   t|  1$$&q)V'W'WXXX L-9< H,,"'DL#(DL  \"j00"&DL#(DL  \"&999"'DL#'DL  \"&;;;"&DL#'DL 99$@VWW%JJ8I8IJJJ6>>&q)M'N'NOOO64  <  	7$dfWtvg66D
$,,,T>>&V     (( 	 	G'5#455 '')))#117<4466   	 	r   c                    | j         j        r|                     |           g }|                                D ]}|                                 |j                                        }| j         j        r|                     |           |D ]c}t          j        |          }	| 	                    |          \  }
}t          d t          |
d         |
d                   D                       }t          |          }|
d         d         |j        j        z
  | j         j        z   }|
d         d         |j        j        z
  | j         j        z
  }| j         j        rt)          dt+          t-          || j         j        z   |z                                }||z  }|s|| j         j        z  }|j        j        |z   |j        _        g }|	D ]R}t3          |          D ]@}|                    t          j        |                     |                     ||d           AS|}	|	D ]}|                     |||           | j         j        rO|j        st=          j         |d                    |	D ](}|                     |||j        z  d|
d                    )|	D ]4}|D ]/}|                      |d         |
|||d         |d         f           05| j         j        r|                     |	           ||	z  }etC          |          S )Nc                 >    g | ]\  }}t          j        ||          S r   )mathisclose)r6   r&   js      r   r8   z/PathAlongPath._do_transform.<locals>.<listcomp>   s(    SSSDAqT\!Q''SSSr   r   r   r   zhThe 'stretch' option requires that the pattern must have non-zero width :
Please edit the pattern width.r1   )"r   rD   flipxyrB   rJ   rL   rM   copydeepcopy	linearizeallziprC   r(   minimumtoffsetr)   centernoffsetr>   maxintroundrG   maximumrangeappendoffsetr?   rF   r   r:   r/   r   )r   	skeletonsp0r*   rQ   newpskelnodecur_skeletoncomprL   r!   r"   skel_closedlengthxoffsetyoffset	nb_copiesrF   newsubr;   ctlpts                         r   rK   zPathAlongPath._do_transform   sU   <  	KKOOO!((** 7	 7	H$$&&&#=5577L|$ *L)))$ 2 2}R(($(NN4$8$8!'!SSCXb\4R4RSSS  W"1+a.46>9DL<PP"1+a.46=84<;OO<&  #As5&4<;M2MQS1S+T+T'U'U V VINE& 4!33%)V^e%;DFNC# 4 4!&y!1!1 4 4AJJt}S'9'9::: KKR33334 D 7 7CKKWg6666<' 	O: #2A!X     $ O OS&4:*=q(1+NNNN  C!$  11!!H$#'"1XuQx0    <( &KK%%%e2f d###r   N)r   )__name__
__module____qualname____doc__r   r/   rS   rK   r   r   r   r   r   -   s`        ++S S S>!- !- !- !-F* * *X<$ <$ <$ <$ <$r   r   __main__)r{   rZ   rV   r   inkex.bezierr   inkex.pathsr   inkex.localizationr   r;   pathmodifierPathModifierr   rx   runr   r   r   <module>r      s   *           & & & & & & 1 1 1 1 1 1    m$ m$ m$ m$ m$L- m$ m$ m$` zMOO r   