
    CPc"                         d Z ddlmZmZmZmZmZmZ ddlZddl	m
Z dZ G d dej                  Zedk    r e                                             dS dS )	a*  
This extension renders a wireframe sphere constructed from lines of latitude
and lines of longitude.

The number of lines of latitude and longitude is independently variable. Lines
of latitude and longtude are in separate subgroups. The whole figure is also in
its own group.

The whole sphere can be tilted towards or away from the veiwer by a given
number of degrees. If the whole sphere is then rotated normally in Inkscape,
any position can be achieved.

There is an option to hide the lines at the back of the sphere, as if the
sphere were opaque.
    )acosatancospisintanN)inkex_gettextgMbP?c                   R     e Zd ZdZd Z fdZd Zd Zd Zd Z	dde
z  ffd	Z xZS )
WireframeSpherez*Writeframe extension, generate a wireframec                     t          t          |                                           }| j        j        dk     r|t          j        d          z  }|S )Nr   )   )scale)superr   container_transformoptionsTILTinkex	Transform)self	transform	__class__s     2/usr/share/inkscape/extensions/wireframe_sphere.pyr   z#WireframeSphere.container_transformC   sK    /400DDFF	<q  w7777I    c                 x   |                     dt          dd           |                     dt          dd           |                     dt          d	d
           |                     dt          dd           |                     dt          dd           |                     dt          j        dd           d S )Nz	--num_latNUM_LAT   )typedestdefaultz
--num_longNUM_LONG   z--radiusRADIUSg      Y@z--tiltr   g     A@z
--rotation
ROT_OFFSET   z--hide_back	HIDE_BACKF)add_argumentintfloatr   Boolean)r   parss     r   add_argumentszWireframeSphere.add_argumentsI   s    +CiLLL,Sz2NNN*5xOOO(VTJJJ,UqQQQK 	 	
 	
 	
 	
 	
r   c              #     K   | j         }|j        dz  dk    r#t          j        t	          d                     d S | j                            t          |j                  dz             }t          |j
                  t          dz  z  }|j        t          z  dz  }|j        dk    r|                     |j        |||          V  |j        dk    r!|                     |j        dz   ||          V  |                     ||fd          V  d S )N   r   z2Please enter an even number of lines of longitude.px   r   r   r   )r   r!   r   errormsg_svgunittouustrr#   absr   r   r$   longitude_linesr   latitude_linesdraw_ellipse)r   optradiustiltrotates        r   generatezWireframeSphere.generateS   s     l <!q  N1QRRSSSF""3sz??T#9::38}}S)"$s* <!&&s|T66JJJJJ;?? %%ckAotVDDDDD  0&9999999r   c                 (   t          j                    }|                    dd           t          d|dz            D ]S}||d|z  z  t          dz  z  z   }|t          k    r|dt          z  z  }t          t          |                    t          |          z  }||z  t          z   |f}	t          |t          |          z  t          |          z  |t          |          z  z            dt          z  z  }
ddt          z  f}| j
        j        r=|t          dz  k    rt          dz  dt          z  dz  f}ndt          z  dz  t          dz  f}|                    |                     |	d|                    }t          j        |
f	          |_        U|S )
 Add lines of latitude as a groupinkscape:labelzLines of Longituder   r.   g     v@     f@   r1   )r>   )r   Groupsetranger   r7   r   r   EPSILONr   r   r&   addr:   r   r   )r   numberr=   r<   r>   grp_longi
long_angleinverseradsrotation	start_endelems                r   r8   zWireframeSphere.longitude_linesl   s    ;==%';<<<
 q&A+&& 	A 	AA1#7BJ"GGJBa"f$
 #j//**SYY6GW$w.7D #j//)CII5&3z??:RS H AFI|% 5a''!#aR! 4II!"R!R!V 4I << 1 1$	 J JKKD"_XK@@@DNNr   c                    t          j                    }|                    dd           d|z  }t          d|          D ]}||z  t          dz  z  }|t          |          z  |t          |          z  t          |          z  t          z   f}d|t          |          z  t          |          z  f}	| j        j	        r||k    r|t          |z
  k    r*|
                    |                     ||	                     t          t          |t          dz  z
            t          t          dz  |z
            z             t          z  dz   }
t          dz  |
t          z  z
  t          dz  |
t          z  z   f}|
                    |                     ||	|                     a|
                    |                     ||	                     |S )rA   rB   zLines of LatituderC   r   r0   r   r.   )r   rE   rF   rG   r   r   rH   r   r   r&   rI   r:   r   r   )r   rJ   r=   r<   grp_lat	delta_latrL   	lat_anglerO   pos
proportionrQ   s               r   r9   zWireframeSphere.latitude_lines   s    +--$&9::: FN	q&!! 	: 	:A"Q284I
 Y'#i..(3t994?D fs9~~-D		9:C|% :t## 29,,D$5$5dC$@$@AAAA #3y26'9#:#:Sa$=O=O#OPPQTVV  #
 &(!Vj2o%=rAv
UW?W$X	D$5$5dC$K$KLLL D--dC889999r   r   r.   c                     t          j        j        |g|R |d         |d         ddd}dt          | j                            d                    dd	|_        |S )
z;Creates an elipse with all the required sodipodi attributesr   r   truearc)startendopenarctypez#0000001pxnone)strokezstroke-widthfill)r   PathElementr[   r6   r4   r5   style)r   r_xyc_xyrQ   paths        r   r:   zWireframeSphere.draw_ellipse   s     $

 
 A,!
 
 
   1 1% 8 899
 


 r   )__name__
__module____qualname____doc__container_labelr   r,   r?   r8   r9   r   r:   __classcell__)r   s   @r   r   r   >   s        44'O    
 
 
: : :2( ( (T& & &P 34QV        r   r   __main__)rl   mathr   r   r   r   r   r   r   inkex.localizationr	   r3   rH   GenerateExtensionr   ri   run r   r   <module>ru      s   ( @ / . . . . . . . . . . . . . . .  1 1 1 1 1 1 O O O O Oe- O O Od zO r   