
    _e6)                     0   d Z ddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZmZ ddlZddlZddlmZ ddlZdd	lmZ d
Z G d de	j*                  ej,                        Z ej.                  e      ej0                  _        d Zej6                  j9                         D ]D  \  ZZ ee      Zeej@                  e<   eej6                  e   k(  sJ ejB                  d   ek(  rDJ  	 [[[d Z$ eej0                        d        Z eejJ                        d        Z%dZ&d Z'd Z( eejR                        d        Z) eejT                        d        Z* eejV                        d        Z+ eejX                        d        Z,y# e"$ r
Z#Y dZ#[#dZ#[#ww xY w)a  Implementation of GLU Nurbs structure and callback methods

Same basic pattern as seen with the gluTess* functions, just need to
add some bookkeeping to the structure class so that we can keep the
Python function references alive during the calling process.
    )GLU)platform
converterswrapper)	glustruct)lazy)arrayserrorN)PLATFORM)_configflags)GLUnurbsgluNewNurbsRenderergluNurbsCallbackgluNurbsCallbackDatagluNurbsCallbackDataEXTgluNurbsCurvegluNurbsSurfacegluPwlCurvec                      e Zd ZdZ ej
                  ej                        Zi Ze	j                   ede	j                        e	j                   ede	j                   ej                  e	j                              e	j                    ed ej                  e	j"                              e	j$                   ed ej                  e	j"                         ej                  e	j                              e	j&                   ed ej                  e	j"                              e	j(                   ed ej                  e	j"                         ej                  e	j                              e	j*                   ed ej                  e	j"                              e	j,                   ed ej                  e	j"                         ej                  e	j                              e	j.                   ed ej                  e	j"                              e	j0                   ed ej                  e	j"                         ej                  e	j                              e	j2                   ed      e	j4                   ed ej                  e	j                              e	j6                   ede	j                        iZe	j                  de	j                  de	j                   de	j$                  de	j&                  de	j(                  de	j*                  de	j,                  de	j.                  de	j0                  de	j2                  de	j4                  de	j6                  diZd ZddZd	 Z d
 Z!y)r   a  GLU Nurbs structure with oor and callback storage support

    IMPORTANT NOTE: the texture coordinate callback receives a raw ctypes
    data-pointer, as without knowing what type of evaluation is being done
    (1D or 2D) we cannot safely determine the size of the array to convert
    it.  This is a limitation of the C implementation.  To convert to regular
    data-pointer, just call yourNurb.ptrAsArray( ptr, size, arrays.GLfloatArray )
    with the size of data you expect.
    N_justOOR_vec3_vec4_texc                       fd}|S )z#Just do OOR on the last argument...c                  D    | d d j                  | d         fz   }  |  S )N)originalObject)argsfunctionselfs    5/usr/lib/python3/dist-packages/OpenGL/GLU/glunurbs.pygetOORz!GLUnurbs._justOOR.<locals>.getOORh   s0    9 3 3DH =??Dd$$     )r    r   r"   s   `` r!   r   zGLUnurbs._justOORf   s    	% r#   c                       fd}|S )zBConvert first arg to size-element array, do OOR on arg2 if presentc                      j                  | d   t        j                        }t        |       dkD  rj	                  | d         } ||      S  |      S )Nr      )
ptrAsArrayr	   GLfloatArraylenr   )r   vecoorr   r    sizes      r!   r+   zGLUnurbs._vec3.<locals>.vecn   sU    //$q'$v/B/BCC4y1}))$q'2c++&r#   r$   )r    r   r-   r+   s   ``` r!   r   zGLUnurbs._vec3l   s    	' 
r#   c                 &    | j                  |d      S )zSize-4 vector version...   )r   )r    r   s     r!   r   zGLUnurbs._vec4v   s    zz8Q((r#   c                       fd}|S )zTexture coordinate callback

        NOTE: there is no way for *us* to tell what size the array is, you will
        get back a raw data-point, not an array, as you do for all other callback
        types!!!
        c                  v    t        |       dkD  r j                  | d         } | d   |      S  | d         S )Nr'   r   )r*   r   )r   r,   r   r    s     r!   r,   zGLUnurbs._tex.<locals>.oor   sB    4y1}))$q'2a#//a**r#   r$   )r    r   r,   s   `` r!   r   zGLUnurbs._texy   s    	+ 
r#   )   )"__name__
__module____qualname____doc__r   functionTypeForr   FUNCTION_TYPECALLBACK_FUNCTION_REGISTRARS_simpleGLU_NURBS_BEGINGLenumGLU_NURBS_BEGIN_DATActypesPOINTERGLvoidGLU_NURBS_VERTEXGLfloatGLU_NURBS_VERTEX_DATAGLU_NURBS_NORMALGLU_NURBS_NORMAL_DATAGLU_NURBS_COLORGLU_NURBS_COLOR_DATAGLU_NURBS_TEXTURE_COORDGLU_NURBS_TEXTURE_COORD_DATAGLU_NURBS_ENDGLU_NURBS_END_DATAGLU_NURBS_ERRORCALLBACK_TYPESWRAPPER_METHODSr   r   r   r   r$   r#   r!   r   r      s    -H,,X\\:M$  	'.."
 	$$m'...&.."@'
 	  -.&..1#
 	%%}.&..1>6>>'..3Q(
 	  -.&..1#
 	%%}.&..1>6>>'..3Q(
 	.&..1"
 	$$m.&..1>6>>'..3Q'
 	''.&..1*
 	,,m.&..1>6>>'..3Q/
 	m
 	""M.&..0%
 	'..!
M)NV 	$$j  '%%w  '%%w$$g'',,ft""JO	)r#   r   c                     t        j                  t        j                        }t	        j
                  t              t        j                  | g|_        |j                  d   | k(  sJ |S )z4Get gluNurbsCallback function with set last arg-typer   )	r   copyBaseFunctionr:   r   r>   r?   r   r<   argtypes)funcTyperesults     r!   _callbackWithTyperT      sT    ''  F ~~h/JFO??2(***Mr#   r   c                 &    | j                  ||      S )z,Dispatch to the nurb's addCallback operation)addCallback)nurbwhichCallBackFuncs      r!   r   r      s    UL22r#   c                      |        }|d   }|S )zAReturn a new nurbs renderer for the system (dereferences pointer)r   r$   )baseFunctionnewSetnews      r!   r   r      s     ^F
)CJr#   c                 2     | ||j                  |            S z6Note the Python object for use as userData by the nurb
noteObjectr[   rW   userDatas      r!   r   r           doox) r#      c           	          | dk  rt        j                  |d|       | t        kD  r!t        j                  |dt        d|       |d| z  k  r!t        j                  d|d|dd| z        y	)
zCheck that order is valid...r'   z should be 1 or more, is z should be z or less, is    zKnotcount must be at least 2x z is z should be at least N)r
   GLUError	MAX_ORDER)order	knotCountnames      r!   
checkOrderrm      s}    qynn26u>
 	
 
	nn37EJ
 	
 
ag	nnQUW`bcdibij
 	
 
r#   c                 ~    t        |       r2| d   }| dd D ]$  }||k  s	t        j                  |d|d|       yy)z'Check that knots are in ascending orderr   r'   Nz has decreasing knot z after )r*   r
   rh   )knotsrl   knotnexts       r!   
checkKnotsrr      sN    
5zQx!"I 	Dd{nn?CT4Q 	 r#   c                 2     | ||j                  |            S r_   r`   rb   s      r!   r   r      rd   r#   c           	         t         j                  j                  |      }t         j                  j                  |      }t         j                  j                  |      }	 t         j                  j	                  |      \  }}||z
  }	t        j                  rt        |	|d       t        |d        | ||||||	|      S # t
        $ r}t        j                  d      d}~ww xY w)zaPythonic version of gluNurbsCurve

    Calculates knotCount, stride, and order automatically
    z"Need a 2-dimensional control arrayNzorder of NURBS curvezknots of NURBS curver	   r)   asArray	arraySize
dimensions
ValueErrorr
   rh   r   ERROR_CHECKINGrm   rr   )
r[   rW   ro   controltyperk   lengthsteperrrj   s
             r!   r   r      s     ''0E##--u6I!!))74GI))44g?t E""E9&<=E12igud   InnFHHIs   "B= =	C CC c                    t         j                  j                  |      }t         j                  j                  |      }t         j                  j                  |      }t         j                  j                  |      }t         j                  j                  |      }	 t         j                  j	                  |      \  }}	}
||z
  }||	z
  }|	|
z  }|
}t        j                  r2t        ||d       t        ||d       t        |d       t        |d       ||z
  ||z
  z  ||	z  k(  s t        j                  d|||||||||||       | |||||||||||      }|S # t
        $ r}t        j                  d      d}~ww xY w)zcPythonic version of gluNurbsSurface

    Calculates knotCount, stride, and order automatically
    z"Need a 3-dimensional control arrayNzsOrder of NURBS surfaceztOrder of NURBS surfacezsKnots of NURBS surfaceztKnots of NURBS surfacezInvalid NURB structureru   )r[   rW   sKnotstKnotsr{   r|   
sKnotCount
tKnotCountr}   widthr~   r   sOrdertOrdersStridetStriderS   s                    r!   r   r      s      ((&2F$$..8J  ((&2F$$..8J!!))74GI"//::GEuT & F%FDjGG""FJ(ABFJ(ABF56F56v
6 12fUlBnn(*fj&Wg6
 	
 j&*f'v	F M5  InnFHHIs   #E 	E;!E66E;c                 &   t         j                  j                  |      }|t        j                  k(  rd}n$|t        j
                  k(  rd}nt        d|z        t         j                  j                  |      }t        ||z        } | |||||      S )zgluPwlCurve -- piece-wise linear curve within GLU context

    data -- the data-array
    type -- determines number of elements/data-point
    rg   r2   zUnrecognised type constant: %s)	r	   r)   rv   r:   GLU_MAP1_TRIM_2GLU_MAP_TRIM_3ry   rw   int)r[   rW   datar|   divisorr-   s         r!   r   r     s     &&.Dw&&&	''	'>EFF(($0DtW}DtT7D::r#   )-r6   
OpenGL.rawr   r:   OpenGLr   r   r   
OpenGL.GLUr   OpenGL.lazywrapperr   _lazyr	   r
   r>   weakrefOpenGL.platformr   r   __all__	GLUStructr   r?   r   restyperT   rM   itemscrR   cbr9   rQ   	NameErrorr   r   r   ri   rm   rr   r   r   r   r   r$   r#   r!   <module>r      s   & 0 0   ,     $  	hy""G$4$4 hV '5fnnh&@   # ++113 'LQx	H	&B13H))1.x..q1111;;r?h&&&	'
		"h3 ##% & $$& ' 	
 '') *   ( !' "'R ; ;m  		s   'F FF